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.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.