[Haskell-cafe] Usage of | in classes

Arthur van Leeuwen arthurvl at cs.uu.nl
Tue Jun 7 10:01:45 EDT 2005


On Tue, Jun 07, 2005 at 03:54:06PM +0200, Frank-Andre Riess wrote:
> Hi,
> 
> Gracjan's question led me to another question:
> 
> > class Monad m => Ref m r | m -> r where
> >      newRef :: a -> m (r a)
> >      readRef :: r a -> m a
> >      writeRef :: r a -> a -> m ()
> 
> What's the meaning of the bar and the function type in this declaration. I've 
> seen something like that before (with state monads, I think), but couldn't 
> find an explanation in the Haskell grammar (or anywhere else on haskell.org).

It is a functional dependency. That is, in this case, the choice of type r 
is uniquely determined by the choice for the type m. See also
http://haskell.org/hawiki/FunDeps and
http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html#functional-dependencies

> Thanks in advance,

My pleasure.

Doei, Arthur.

-- 
  /\    / |       arthurvl at cs.uu.nl       | Work like you don't need the money
 /__\  /  | A friend is someone with whom | Love like you have never been hurt
/    \/__ | you can dare to be yourself   | Dance like there's nobody watching


More information about the Haskell-Cafe mailing list