= Solution
The <Haskell> <type signatures> are \b[`take :: Int -> [a] -> [a]` and `drop :: Int -> [a] -> [a]`]. These definitions also handle nonpositive counts as the Prelude does:
``
take n _ | n <= 0 = []
take _ [] = []
take n (x:xs) = x : take (n-1) xs
drop n xs | n <= 0 = xs
drop _ [] = []
drop n (_:xs) = drop (n-1) xs
``
The wildcard in the first equation matters under <lazy evaluation>: `take 0 undefined` yields `[]` without inspecting its <list> argument. The remainder of this question uses nonnegative counts.<Haskell 2010 Language Report>[§9, Standard Prelude, definitions and types of take and drop]{ref}
Back to article page