[Haskell-cafe] Re: Reinvention

Andrew Coppin andrewcoppin at btinternet.com
Wed Jun 27 15:35:31 EDT 2007


J. Garrett Morris wrote:
> More generally, that's unfoldr:
>
> Prelude> :t Data.List.unfoldr
> Data.List.unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
>
> unfoldr represents the end of the unfold explicitly (using Nothing)
> instead of implicitly (using the empty list).

Duh... of course it does. :-S

Silly thing is, I use unfoldr all the time - for converting integers to 
bits. *sigh*

Of course, that solves the problem of just wanting to chop the input 
into chunks. It works less well if you want to do complicated recursive 
stuff. But IIRC the Parsec library supports parsing of arbitrary tokens 
(although presumably they have to be in Eq?) so maybe I should revise 
that...



More information about the Haskell-Cafe mailing list