[Haskell-cafe] monad example
Damien Mattei
damien.mattei at gmail.com
Wed Apr 17 14:06:12 UTC 2019
hello,
i still seaching a good monad example and after passed the classic
tutorial about Maybe monad or State monad which is found in almost 90%
of the litterature i try to learn in deep the example of monad that
talk about probability (
http://learnyouahaskell.com/for-a-few-monads-more )
for this i try to trace the calls of the inner monad definition like in
the file, i give the file in attachment (monade.hs) and the output has
a lot of garbage data, not the nicer way to display it,sorry.
What i can not figure out is at what stage the program construct the
[Tails,Heads] , [Heads,Heads] ... etc
i do not know,
if someone could explain me in detail the action of
a <- coin
b <- loadedCoin
return [a,b]
step by step it would be of great help...
Regards,
Damien
note:
here is the ouput:
*Main> :load monade.hs
[1 of 1] Compiling Main ( monade.hs, interpreted )
Ok, one module loaded.
*Main> flipTwoVal
Prob {getProb = (Monad Prob >>=
flatten
(fmap f m)
Functor Prob
Functor Prob (f x,1 % 2)
flatten multAll map ... p= 1 % 2
(Monad Prob >>=
flatten
(fmap f m)
Functor Prob
Functor Prob (f x,1 % 10)
flatten multAll map ... p= 1 % 10
Monad Prob return)
[ flatten multAll (1 % 10*1 % 1)
flatten multAll (1 % 2*1 % 10)
([Heads,Heads],1 % 20) Functor Prob (f x,9 % 10)
flatten multAll map ... p= 9 % 10
Monad Prob return)
, flatten multAll (9 % 10*1 % 1)
flatten multAll (1 % 2*9 % 10)
([Heads,Tails],9 % 20) Functor Prob (f x,1 % 2)
flatten multAll map ... p= 1 % 2
(Monad Prob >>=
flatten
(fmap f m)
Functor Prob
Functor Prob (f x,1 % 10)
flatten multAll map ... p= 1 % 10
Monad Prob return)
, flatten multAll (1 % 10*1 % 1)
flatten multAll (1 % 2*1 % 10)
([Tails,Heads],1 % 20) Functor Prob (f x,9 % 10)
flatten multAll map ... p= 9 % 10
Monad Prob return)
, flatten multAll (9 % 10*1 % 1)
flatten multAll (1 % 2*9 % 10)
([Tails,Tails],9 % 20)]}
*Main> flipTwoVal
Prob {getProb = [([Heads,Heads],1 % 20),([Heads,Tails],9 %
20),([Tails,Heads],1 % 20),([Tails,Tails],9 % 20)]}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190417/be474110/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: monade.hs
Type: text/x-haskell
Size: 3155 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190417/be474110/attachment.hs>
More information about the Haskell-Cafe
mailing list