[Haskell-beginners] Re: Built-in/more elegant version of this function?

Jordan Cooper nefigah at gmail.com
Mon Oct 26 19:48:25 EDT 2009


Am Montag 26 Oktober 2009 18:49:51 schrieb Jordan Cooper:
>> I was wondering if there is a built-in way to do what this function I
>> wrote does (or at least a more elegant way, preferably without
>> explicit recursion).
>>
>> f xss = map safeHead xss : f (map safeTail xss)
>>
>> (where safeHead/Tail are versions of head/tail that don't crash on []
>> input)
>
>Not quite the same, but
>
>Prelude> :m +Data.List
>Prelude Data.List> transpose [[1,2],[],[3,4,5]]
>[[1,3],[2,4],[5]]
>
>could be more or less what you want.

Thank you, I think that will work nicely!


More information about the Beginners mailing list