Help needed in understanding MonadWriter syntax.

Hi, I'm trying to understand the MonadWriter class definition syntax. Now, I'm using GHC 7.6 and the class is defined as class (Monoid w, Monad m) => MonadWriter w m | m -> w where .... I've never seen '|' in the middle of a class definition, could some one explain this? It's used in the guard syntax as well as to separate data constructors in a type definition. Regards Vinay

This is functional dependency. For this case It means for given monad
m, there is unique possible value of Monoid w.
http://en.wikipedia.org/wiki/Type_class#Functional_dependencies
http://research.microsoft.com/pubs/67435/jfp06.pdf
Thanks
Divyanshu Ranjan
On Mon, Sep 16, 2013 at 10:30 AM, Vinay Emani
Hi,
I'm trying to understand the MonadWriter class definition syntax. Now, I'm using GHC 7.6 and the class is defined as
class (Monoid w, Monad m) => MonadWriter w m | m -> w where ....
I've never seen '|' in the middle of a class definition, could some one explain this? It's used in the guard syntax as well as to separate data constructors in a type definition.
Regards Vinay
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Mon, Sep 16, 2013 at 12:00 PM, Vinay Emani
I've never seen '|' in the middle of a class definition, could some one explain this? It's used in the guard syntax as well as to separate data constructors in a type definition.
You're quite right. The vertical bar is used in /defining/ (1) a /typeclass/ that has functional dependencies (2) a /function/ using pattern guards (3) a /datatype/ that is a sum of two or more datatypes. These are all different, as you've guessed. The reason the syntax conflation works is that all these constructs are different. The canonical intro to fundeps is the container/element example. See Section 3 on collection types in http://web.cecs.pdx.edu/~mpj/pubs/fundeps.html -- Kim-Ee
participants (3)
-
divyanshu ranjan
-
Kim-Ee Yeoh
-
Vinay Emani