I'm reading the Monads chapter in Real World Haskell (chapter 14).
A function is defined as follows:
type RandomState a = State StdGen a
getRandom :: Random a => RandomState a
getRandom =
get >>= \gen ->
let (val, gen')= random gen in
put gen' >>
return val
I don't really understand the purpose of the get and put funct...
In chapter 15 of Real World Haskell, a type class is defined:
class (Monad m) => MonadSupply s m | m -> s where
A couple paragraphs later, it says that >>= and return don't need to be defined because of the context. But there's no further explanation of what it means by context.
How does the compiler know MonadSupply is an instance ...
The followng snippet contains a solution for exercise 3 on page 69 (write a function mean to calculate the mean of a list).
While writing some QuickCheck tests to verify whether the its results are more or less sane, I found that on my system (ghc 6.12.3, Haskell Platform 2010.2.0.0 on 32-but Ubuntu 10.4) the tests work for Integer inpu...