开发者

Syntax of MonadState typeclass declaration [duplicate]

开发者 https://www.devze.com 2023-03-20 17:39 出处:网络
This question already has answers here: Closed 11 year开发者_StackOverflow社区s ago. Possible 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

精彩评论

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

关注公众号