HaskellRecords.curry 593 Bytes
Newer Older
1
module HaskellRecords where
2

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
-- data R a = C { l :: Int, x :: a }
--          | D { l :: Int }
--
-- -- construction
-- r1 :: R Bool
-- r1 = C { l = 42, x = True }
--
-- r2 :: R a
-- r2 = C {}
--
-- -- pattern matching
-- fun :: R a -> Bool
-- fun C { l = 42 } = True
--
-- fun2 :: R a -> Bool
-- fun2 C {} = False
--
-- -- update
-- upd :: R Bool -> R Bool
-- upd r = r { x = False, l = 0 }
--
-- -- selection
-- getL :: R a -> Int
-- getL r = l r
27

28
data R = C { label :: Int, l2 :: Bool }
29

30 31
r :: R
r = C { label = 42, l2 = True }
32

33 34
r' :: R
r' = r { label = 73 }
35

36 37
unr :: R
unr = C { l2 = True }