[Haskell-beginners] Re: Simplifying a 'split' function
Ertugrul Soeylemez
es at ertes.de
Wed Apr 29 15:56:05 EDT 2009
Ben Sanders <bwsanders at gmail.com> 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)?
No.
> And is there any other nicer way to write it?
Yes:
split = fmap return
Greets,
Ertugrul.
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/
More information about the Beginners
mailing list