Commit e4a420e9 authored by Jan Rasmus Tikovsky 's avatar Jan Rasmus Tikovsky
Browse files

Updated tests for new record syntax

parent 3b6530c8
module HaskellRecords where module HaskellRecords where
data R a = C { l :: Int, x :: a } -- data R a = C { l :: Int, x :: a }
| D { l :: Int } -- | 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
-- construction data R = C { label :: Int, l2 :: Bool }
r1 :: R Bool
r1 = C { l = 42, x = True }
r2 :: R a r :: R
r2 = C {} r = C { label = 42, l2 = True }
-- pattern matching r' :: R
fun :: R a -> Bool r' = r { label = 73 }
fun C { l = 42 } = True
fun2 :: R a -> Bool unr :: R
fun2 C {} = False unr = C { l2 = True }
-- update
upd :: R Bool -> R Bool
upd r = r { x = False, l = 0 }
-- selection
getL :: R a -> Int
getL r = l r
\ No newline at end of file
module RecordTest where module RecordTest (Agent, lastName, trueIdentity, mike) where
import HaskellRecords data Person = Person { firstName :: String, lastName :: String }
| Agent { lastName :: String, trueIdentity :: Person }
r = C 73 False mike :: Person
\ No newline at end of file mike = Person { firstName = "Mike", lastName = "Smith" }
\ No newline at end of file
module RecordTest2 where module RecordTest2 where
import RecursiveRecords import RecordTest
updLN = mike { lastName = "Doe" }
showR :: R Int -> String
showR r = show (r :> f1) ++ (r :> f2)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment