[Haskell-cafe] monads with take-out options

Jonathan Cast jonathanccast at fastmail.fm
Wed Nov 26 14:16:53 EST 2008


On Wed, 2008-11-26 at 19:09 +0000, Jules Bean wrote:
> Greg Meredith wrote:
> > Haskellians,
> > 
> > Some monads come with take-out options, e.g.
> > 
> >     * List
> >     * Set
> > 
> > In the sense that if unit : A -> List A is given by unit a = [a], then 
> > taking the head of a list can be used to retrieve values from inside the 
> > monad.
> > 
> > Some monads do not come with take-out options, IO being a notorious example.
> > 
> > Some monads, like Maybe, sit on the fence about take-out. They'll 
> > provide it when it's available.
> 
> To amplify other people's comments:
> 
> List A is just as on the fence as Maybe. "[]" plays the role of "Nothing".
> 
> Some monads require that you put something in, before you take anything 
> out [r -> a, s -> (a,s), known to their friends as reader and state]
> 
> Error is similar to Maybe, but with a more informative Nothing.
> 
> Most monads provide some kind of
> 
> runM :: ## -> m a -> ## a

More precisely,

    runM :: f (m a) -> g a

Where f and g are usually functors.

Maybe, of course, has the nice property that g = m.

jcc




More information about the Haskell-Cafe mailing list