[Haskell-cafe] Unique monad?

Edward Kmett ekmett at gmail.com
Mon Mar 30 15:49:00 EDT 2009


Well, there are a few approaches available.

On the supply front you have the MonadSupply and MonadUnique proposals from
the wiki:

http://www.haskell.org/haskellwiki/New_monads/MonadSupply
http://www.haskell.org/haskellwiki/New_monads/MonadUnique

and of course, the ability to roll your own using the State monad.

Somewhat more satisfying at least my my esoteric interests, is that if
you're willing to turn your entire thinking on its ear there is a unique
supply comonad.

http://comonad.com/haskell/category-extras/dist/doc/html/category-extras/Control-Comonad-Supply.html

which I seem to recall was also available as Data.Supply.

The main issue with generalizing consumption of input is what does it
entail? when you are parsing a list do you have one element at a time
consumption? or do you have the ability to grab a whole prefix at once?
These issues tend to push you towards the use of the State monad anyways.

-Edward Kmett

On Mon, Mar 30, 2009 at 3:29 PM, Andrew Coppin
<andrewcoppin at btinternet.com>wrote:

> Maybe I'm just being blind here, but I don't see a monad transformer (or
> even a monad) in the standard libraries for producing "unique" values. Have
> I missed something?
>
> Related, I don't see a monad for gradually consuming input. We've got the
> Reader monad, but that appears to just give you global access to a single
> monolithic value. That value could be some kind of collection, but there's
> no way to track where you've read up to (or efficiently access that point).
> We've got Parsec, which is a pretty efficient and powerful text parser. But
> what if you don't need full parsing capabilities? You just need to consume
> input, but you're not exactly sure where you're going to consume it? The
> Writer monad seems to let you incrimentally write values out, but there's no
> matching monad for incrimentally reading stuff back in.
>
> (I guess ultimately you can build all these specialised monads out of the
> general State monad if you want. I'm just surprised they're not already
> defined somewhere...)
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090330/0321e086/attachment.htm


More information about the Haskell-Cafe mailing list