diff --git a/exercises/Set5a.hs b/exercises/Set5a.hs index db806c7..61e7f47 100644 --- a/exercises/Set5a.hs +++ b/exercises/Set5a.hs @@ -245,14 +245,16 @@ data OneOrTwo a = One a | Two a a -- Also define the functions toList and fromList that convert between -- KeyVals and lists of pairs. -data KeyVals k v = KeyValsUndefined +data KeyVals k v = Empty | Pair k v (KeyVals k v) deriving Show toList :: KeyVals k v -> [(k,v)] -toList = todo +toList (Pair k v kvList) = (k, v) : (toList kvList) +toList Empty = [] fromList :: [(k,v)] -> KeyVals k v -fromList = todo +fromList ((k,v):xs) = Pair k v (fromList xs) +fromList _ = Empty ------------------------------------------------------------------------------ -- Ex 11: The data type Nat is the so called Peano