mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
5a ex10
This commit is contained in:
+5
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user