开发者

Syntax of MonadState typeclass declaration [duplicate]

This question already has answers here: Closed 11 year开发者_StackOverflow社区s ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜