I wrote my own function takein Haskell as follows:
take' :: (Integral n, Eq a) => n -> [a] -> [a]
take' n lst
| n <= 0 = []
| lst == [] = []
| otherwise = (head lst) : (take' (n-1) $ tail lst)
and it works well.
But when I try to write the same function using the as (@) pattern in the function arguments, it seems that the function does not recognize the second security parameter:
take' :: (Integral n, Eq a) => n -> [a] -> [a]
take' n lst@(hd:tl)
| n <= 0 = []
| lst == [] = []
| otherwise = hd : (take' (n-1) $ tl)
When I try take' 20 []in ghci, I get an error Non-exhaustive patterns in function take'.
What am I doing wrong?
Thanks, Spel.
Spela source
share