[Haskell-beginners] function defenition. Do I understand it right?

Thomas haskell at phirho.com
Tue Jul 12 11:57:49 CEST 2011


On 12.07.2011 11:44, Roelof Wobben wrote:

> So I thought this would work .
> halve (xs) | length xs == 0 = []

This returns a list

>             | length xs `mod`2 == 0 = (take n xs, drop n xs)
>             | otherwise = (take (n+1) xs, drop (n+1) xs)

These return a pair of two lists each.

>
>     where n = length xs `div`2

You probably want to return a pair of empty lists in the first case, too.

HTH,
Thomas




More information about the Beginners mailing list