[Haskell-beginners] Simplifying a 'split' function

Thomas Davie tom.davie at gmail.com
Wed Apr 29 15:55:05 EDT 2009


On 29 Apr 2009, at 21:00, Ben Sanders wrote:

> In looking through a merge sort implementation example, I came  
> across this code:
>
> split :: [a] -> [[a]]
> split [] = []
> split (x:xs) = [x] : split xs
>
> I would have written the same code as
>
> split :: [a] -> [[a]]
> split = map (: [])
>
> Is there any particular difference here (other than explicit
> recursion)?  And is there any other nicer way to write it?

How about map pure.  I do like the robot monkey though :)

Bob


More information about the Beginners mailing list