[Haskell] Do the libraries define S' ?

David Menendez zednenem at psualum.com
Thu Jul 8 20:36:57 EDT 2004


Conor T McBride writes:

> As some of you know, I like them a lot too. In fact, if you have a
> return-like thing and an ap-like thing, you can make fmap as well.
> (Note that the return for the environment monad is none other than
> S's best friend K.)
> 
> So I got hacking, a little while ago...
> 
>    infixl 9 <%>  -- my name for <# -- others have other names
>    class Idiom i where
>      idi :: x -> i x
>      (<%>) :: i (s -> t) -> i s -> i t
> 
> I call them idioms because it's like having the apparatus
> of applicative programming, just in a different (perhaps impure)
> idiom.
> 
> [I only just found out that they show up under the name Sequence
>   in the experimental Control.Sequence module. I should have known.
>   It's part of the Arrow stuff, and these things are an interesting
>   species of Arrow. As far as I know, it was Ross Paterson who
>   identified them in the categorical jungle as weakly symmetric lax
>   monoidal functors.]

I've also seen this referred to as a pointed functor[1] and a
premonad[2].

So here's yet another definition of Monad:

    class Functor f where
      fmap :: (a -> b) -> f a -> f b
    
    class Functor p => Premonad p where
      return :: a -> p a
    
    class Premonad m => Monad m where
      join  :: m (m a) -> m a
      (>>=) :: m a -> (a -> m b) -> m b
      
      join m  = m >>= id
      m >>= k = join (fmap k m)

[1] Composing Monads Using Coproducts 
    <http://www.informatik.uni-bremen.de/~cxl/papers/icfp02.pdf>
[2] Composing Monads <http://www.cse.ogi.edu/~mpj/pubs/composing.html>
-- 
David Menendez <zednenem at psualum.com> <http://www.eyrie.org/~zednenem/>


More information about the Haskell mailing list