Skip to content

Commit dd53d46

Browse files
committed
added example generics cases
1 parent e48d07a commit dd53d46

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

chapter10/generics.hs

+15-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ class GEq a where
3131
default geq :: (Generic a, GEq' (Rep a)) => a -> a -> Bool
3232
geq x y = geq' (from x) (from y)
3333

34-
instance GEq Char where geq = (==)
35-
instance GEq Int where geq = (==)
36-
instance GEq Float where geq = (==)
34+
-- Base equalities
35+
instance GEq Char where geq = (==)
36+
instance GEq Int where geq = (==)
37+
instance GEq Float where geq = (==)
38+
39+
-- Equalities derived from structure of (:+:) and (:*:)
40+
instance GEq a => GEq (Maybe a)
41+
instance (GEq a, GEq b) => GEq (a,b)
42+
43+
main :: IO ()
44+
main = do
45+
print $ geq 2 (3 :: Int)
46+
print $ geq 'a' 'b'
47+
print $ geq (Just 'a') (Just 'a')
48+
print $ geq ('a','b') ('a', 'b')

chapter9/assign/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Assign
2+
------
3+
4+
```bash
5+
$ stack exec assign input.test
6+
```

chapter9/assign/happy.cabal renamed to chapter9/assign/assign.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cabal-version: >=1.10
66

77
executable assign
88
build-depends:
9-
base >= 4.6 && <4.7
9+
base >= 4.6 && <4.9
1010
, containers >= 0.5 && <0.6
1111
, mtl >= 2.2
1212
default-language: Haskell2010

chapter9/assign/stack.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resolver: lts-3.16
2+
packages:
3+
- '.'
4+
extra-deps: []
5+
flags: {}
6+
extra-package-dbs: []

chapter9/attoparsec/simple.ml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(\x -> x)

0 commit comments

Comments
 (0)