You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to introduction-to-funct...@googlegroups.com
uppgift 7 är fel också!
Anders
unread,
Oct 20, 2012, 4:44:31 AM10/20/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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==)