[Haskell-beginners] let , equations, and monads

PATRICK BROWNE patrick.browne at dit.ie
Tue Nov 3 12:24:46 UTC 2015


Chaddaï,
Thank you very much for your response to my question. It confirms my
intuition, but I was not sure.

Is it true in general that let expressions (e.g. eligibleLet) are always
semantically equivalent to their equational  counterparts (e.g.
eligibleEquational)? Would it be fair to say that "let" is syntactic sugar
for an equational equivalent? Or is there more to it?
With respect to the ordering of the operations is generally true that a
monadic version is semantically equivalent to a set of "let expressions"
in a nested if-then-else?

Thanks,
Pat

On 3 November 2015 at 06:56, Chaddaï Fouché <chaddai.fouche at gmail.com>
wrote:

> Hello,
>
> Le mer. 28 oct. 2015 à 15:59, PATRICK BROWNE <patrick.browne at 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ï
>

-- 


This email originated from DIT. If you received this email in error, please 
delete it from your system. Please note that if you are not the named 
addressee, disclosing, copying, distributing or taking any action based on 
the contents of this email or attachments is prohibited. www.dit.ie

Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí 
earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an 
seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon 
dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa 
ríomhphost nó sna hiatáin seo. www.dit.ie

Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to 
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151103/8a523e1a/attachment.html>


More information about the Beginners mailing list