loading...

re: Haskell by example - The birthday bar VIEW POST

FULL DISCUSSION
 

I thinking I've got the idea how to solve the problem.
Basically I need to turn this list [1,2,3,4,5] into this
[[1,2],[2,3],[3,4],[4,5]].

I wrecked my brain and couldn't come up with the solution so I picked at yours and tried the slice function separately.

slice b m
| length b >= m = take m b : slice (tail b)
| otherwise = []

But the ghci yells at me:

birthday_chocolate.hs:42:1: error:
• Couldn't match type ‘Int -> [[a]]’ with ‘[[a]]’
Expected type: [a] -> [[a]]
Actual type: [a] -> Int -> [[a]]
• Relevant bindings include
slice :: [a] -> [a]
Failed, modules loaded: none.

 

Now I see I called slice only on one argument.
It should have been slice (tail b) m.

code of conduct - report abuse