[Haskell-cafe] Re: Laziness and Either
David Roundy
droundy at darcs.net
Wed Apr 23 09:40:06 EDT 2008
On Wed, Apr 23, 2008 at 01:12:16PM +0200, apfelmus wrote:
> I think that using [Maybe a] for this purpose is too fine-grained, I
> would use a custom list type
>
> data River a = a :< (River a) | Done | Error
>
> (I didn't want to call it Stream because that name is too overloaded
> already and PartialList is too long :) The three constructors
> correspond to the three cases you mention. In particular, Error takes
> the role of the last Nothing .
That sounds like a good idea. But I'd call it Creek, because a river is
present year-round, while a creek sometimes dries up in the summer. :) And
I'd also vote for adding a String (or more generic parameter) to the Error
type, so you can give some sort of reporting when something goes wrong.
String is appealing, because then you could make Creek a monad, and fail
could generate a nice Error message (assuming fail = Error).
Of course, you could take the silly metaphor even further
data Creek a = a :< (Creek a) | Ocean | Drought String
:)
--
David Roundy
Department of Physics
Oregon State University
More information about the Haskell-Cafe
mailing list