Hello,

Le mer. 28 oct. 2015 à 15:59, PATRICK BROWNE <patrick.browne@dit.ie> a écrit :

{- From Learn Haskell Fast and Hard : 4.3.1.  Maybe is a monad
 http://yannesposito.com/Scratch/en/blog/Haskell-the-Hard-Way/#maybe-monad
 
 Concerning the code below I have the following questions:
 1) Are eligibleLet and eligibleEquational operationally equivalent (i.e. perform the same operations) and/or semantically equivalent(i.e. Church-Rosser)?


A priori, they're only semantically equivalent since in eligibleEquational intermediary computation are repeated whereas in eligibleLet they're only effectued once.
 

 2) Apart from the return type of Maybe instead of Bool how does eligibleMonad differ from eligibleLet?


eligibleMonad is nice and readable while eligibleLet is a tiresome mess to write and maintain...
Basically in eligibleMonad the logic that checks whether  an operation is possible is rolled into the monadic operations themselves whereas in eligibleLet you have to check every operation validity yourself (so you can forget one or do it incorrectly).

Note that with more familiarity with monads, you would probably rewrite eligibleMonad to avoid naming the intermediary account (and thus avoid any confusion between versions) :

eligibleMonad account = depositM 100 account
  >>= withdrawM 200
  >>= depositM 100
  >>= withdrawM 300
  >>= depositM 1000
  >> Just True

This would make it very easy to add or remove operations.


--
Jedaï