Theory and Design of PL (CS 538)
February 05, 2020
newtype declarationchar for character[a] for list of elements of same typeMkPaira and b give a type Pair a bdata Person = MkPerson
String -- Name
Bool -- Is employed?
Bool -- Is married?
Int -- Age
String -- Addressdata Person = MkPerson
{ name :: String -- Name
, employed :: Bool -- Is employed?
, married :: Bool -- Is married?
, age :: Int -- Age
, address :: String -- Address
}-- Keep all fields the same, except for name and address:
defaultPerson' = defaultPerson
{ name = "Jane Doe"
, address = "456 Main Street, Anytown, WI }ColorHoursMinutes and MinutesTime in exactly two ways:
HoursMinutes 11 59 :: TimeMinutes 1800 :: TimeMaybe a is either nothing, or an aNothing case isn’t handledNothing is usually indicates failureEither is just a sum with two type parameters:data Either a b = Left a | Right b
-- Auto-generated: Left :: a -> Either a b
-- Auto-generated: Right :: b -> Either a bLeft or Right to create an Either a bMaybe, do a case analysis:a: type of list elements