This commit is contained in:
Aaro Koivukangas
2025-12-23 01:13:55 +02:00
parent b30ca1540e
commit 501d13ddb3
+5 -3
View File
@@ -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