What is context in a Haskell multicamera class?

Chapter 15 of Real World Haskell defines a class of type:

class (Monad m) => MonadSupply sm | m -> s where 

A few paragraphs later, he says that β†’ = and the return does not need to be determined due to context. But there is no explanation of what this means in context.

How does the compiler know that MonadSupply is an instance of Monad, if only "m" is an instance of Monad?

+7
haskell monads typeclass
source share
1 answer

"Context" is just the part between class and => , which in this case is a limitation of Monad m . And it’s not so much that he β€œknows”, moreover, that he uses it - writing a MonadSupply instance for type m , which also does not have a Monad instance, will lead to a compiler error.

+6
source share

All Articles