
On Monday 11 April 2011 17:18:44, Amitava Shee wrote:
I can across the following construct in ghc source
class (Monad m) => MonadState s m | m -> s where get :: m s put :: s -> m ()
I am not aware of the syntactic construct | m -> s just before the where? Can someone please explain it?
It introduces a "functional dependency" (look up FunctionalDependencies in the GHC users' guide, section 7.??). The '|' separates the instance head (MonadState s m) from the functional dependenc(y|ies). Here there's one FunDep, m -> s, saying the class parameter m (the monad) determines the class parameter s (the state). So for each monad m, there can be at most one state type s such that m is a 'stateful monad' with state s. If you're already familiar with type families, the remark that this functional dependency is roughly equivalent to class (Monad m) => MonadState m where type MState m :: * get :: m (MState m) put :: MState m -> m () might be helpful.
Thanks & Regards, Amitava Shee