From 501d13ddb334e6e8d99ca4bfa329a574c9270e34 Mon Sep 17 00:00:00 2001 From: Aaro Koivukangas Date: Tue, 23 Dec 2025 01:13:55 +0200 Subject: [PATCH] 5a ex10 --- exercises/Set5a.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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