user1065942
user1065942

Reputation:

A strange typeclass in Haskell. what's "class (Eq e, GenExpr e, MonadRandom m) => GenProg m e | e -> m where"

class (Eq e, GenExpr e, MonadRandom m) => GenProg m e | e -> m where

Excactly, I can't understand this GenProg m e | e -> m

I guess GenProg is a constructor.

does that means: the one whose pattern matched GenProg m e or e -> m, whose instance can be defined ?

by the way, where can i get all syntax in haskell?

Upvotes: 2

Views: 192

Answers (1)

Daniel Fischer
Daniel Fischer

Reputation: 183873

It's a multiparameter type class with a functional dependency. GenProg is the name of the class, the two parameters are m (which has to be an instance of MonadRandom) and e (which has to be an instance of Eq and GenExpr). Then the | separates the instance head from the functional dependency e -> m, which says that the type e in an instance determines the type constructor m, in other words, for any type e there can be at most one m such that an

instance GenProg m e where ...

appears in a valid programme. (I.e., if there is more than one such instance declaration with the same e, there will be a compilation error.)

Upvotes: 7

Related Questions