mirror of
https://github.com/sdiehl/write-you-a-haskell.git
synced 2024-10-05 15:29:04 +03:00
added example generics cases
This commit is contained in:
parent
e48d07acd7
commit
dd53d46d0f
@ -31,6 +31,18 @@ class GEq a where
|
|||||||
default geq :: (Generic a, GEq' (Rep a)) => a -> a -> Bool
|
default geq :: (Generic a, GEq' (Rep a)) => a -> a -> Bool
|
||||||
geq x y = geq' (from x) (from y)
|
geq x y = geq' (from x) (from y)
|
||||||
|
|
||||||
instance GEq Char where geq = (==)
|
-- Base equalities
|
||||||
instance GEq Int where geq = (==)
|
instance GEq Char where geq = (==)
|
||||||
instance GEq Float where geq = (==)
|
instance GEq Int where geq = (==)
|
||||||
|
instance GEq Float where geq = (==)
|
||||||
|
|
||||||
|
-- Equalities derived from structure of (:+:) and (:*:)
|
||||||
|
instance GEq a => GEq (Maybe a)
|
||||||
|
instance (GEq a, GEq b) => GEq (a,b)
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
print $ geq 2 (3 :: Int)
|
||||||
|
print $ geq 'a' 'b'
|
||||||
|
print $ geq (Just 'a') (Just 'a')
|
||||||
|
print $ geq ('a','b') ('a', 'b')
|
||||||
|
6
chapter9/assign/README.md
Normal file
6
chapter9/assign/README.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Assign
|
||||||
|
------
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ stack exec assign input.test
|
||||||
|
```
|
@ -6,7 +6,7 @@ cabal-version: >=1.10
|
|||||||
|
|
||||||
executable assign
|
executable assign
|
||||||
build-depends:
|
build-depends:
|
||||||
base >= 4.6 && <4.7
|
base >= 4.6 && <4.9
|
||||||
, containers >= 0.5 && <0.6
|
, containers >= 0.5 && <0.6
|
||||||
, mtl >= 2.2
|
, mtl >= 2.2
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
6
chapter9/assign/stack.yaml
Normal file
6
chapter9/assign/stack.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
resolver: lts-3.16
|
||||||
|
packages:
|
||||||
|
- '.'
|
||||||
|
extra-deps: []
|
||||||
|
flags: {}
|
||||||
|
extra-package-dbs: []
|
1
chapter9/attoparsec/simple.ml
Normal file
1
chapter9/attoparsec/simple.ml
Normal file
@ -0,0 +1 @@
|
|||||||
|
(\x -> x)
|
Loading…
Reference in New Issue
Block a user