Fel facit

50 views
Skip to first unread message

Maria

unread,
Oct 19, 2012, 6:20:36 AM10/19/12
to introduction-to-funct...@googlegroups.com
Hejsan!

Jag såg att facit för exam 2012-08 inte stämmer överens med uppgifterna på tentan på uppg 1 och 4.

/Maria

Aangkat

unread,
Oct 20, 2012, 3:42:28 AM10/20/12
to introduction-to-funct...@googlegroups.com
uppgift 7 är fel också!

Anders

unread,
Oct 20, 2012, 4:44:31 AM10/20/12
to introduction-to-funct...@googlegroups.com
Jag tror svaret på uppgift 7 är rätt i facit?

Här kommer ett antal möjliga svar på uppgift 1 och 4:

-- Problem 1:

-- Recursive version with guards:
occurs :: Eq a => a -> [a] -> Int
occurs x []                 = 0
occurs x (y:ys) | x == y    = 1 + occurs x ys
                | otherwise = occurs x ys

-- Recursive version with if-then-else:
occurs1 :: Eq a => a -> [a] -> Int
occurs1 x []     = 0
occurs1 x (y:ys) = if x == y then 1 + occurs1 x ys else occurs1 x ys

-- Version with list-comprehension
occurs2 :: Eq a => a -> [a] -> Int
occurs2 x ys = length [ x | y <- ys, x == y ]

-- Another version wiht list-comprehension
occurs3 :: Eq a => a -> [a] -> Int
occurs3 x ys = sum [ 1 | y <- ys, x == y ]

-- One version with filter
occurs4 :: Eq a => a -> [a] -> Int
occurs4 x ys = length (filter (x==) ys)

-- Shorter version with filter
occurs5 :: Eq a => a -> [a] -> Int
occurs5 x = length . filter (x==)



-- Problem 4:

prop_Reverse_Length :: [Int] -> Bool
prop_Reverse_Length xs = length xs == length (reverse xs)

Legogris

unread,
Oct 21, 2012, 11:51:42 AM10/21/12
to introduction-to-funct...@googlegroups.com
Litet fel i tentan från augusti med:
I exampelfilsystemet i sista uppgiften står tontarna.mp3 med direkt under Swedish-mappen, men i förväntat resultat ligger den under Kent.
Ingen stor gej, men kanske kan förvirra någon.
Reply all
Reply to author
Forward
0 new messages