Syntax of MonadState typeclass declaration [duplicate]
Possible Duplicate:
What's the “|” for in a Haskell class definition?
I'm pretty new to Haskell. In the documentation of MonadState I see the following:
class Monad m => MonadState s m | m -> s where
get :: m s
put :: s -> m ()
What is the | m -> s
syntax here?
It's called a functional dependency or fundep for short. The syntax
class Monad m => MonadState s m | m -> s where
means, that there is only one instance for each m
or - in other words, that if m
is known, the compiler can infer the type of s
form that. Using fundeps makes coding a lot easier, because the compiler can infer much more.
精彩评论