[Haskell-cafe] Proposal: Non-recursive let

i c ivan.chollet at gmail.com
Mon Jul 22 17:09:15 CEST 2013


On Wed, Jul 10, 2013 at 9:47 AM, <oleg at okmij.org> wrote:

>
> Jon Fairbairn wrote:
> > It just changes forgetting to use different variable names because of
> > recursion (which is currently uniform throughout the language) to
> > forgetting to use non recursive let instead of let.
>
> Let me bring to the record the message I just wrote on Haskell-cafe
>
> http://www.haskell.org/pipermail/haskell-cafe/2013-July/109116.html
>
> and repeat the example:
>
> In OCaml, I can (and often do) write
>
>         let (x,s) = foo 1 [] in
>         let (y,s) = bar x s in
>         let (z,s) = baz x y s in ...
>
> In Haskell I'll have to uniquely number the s's:
>
>         let (x,s1)  = foo 1 [] in
>         let (y,s2)  = bar x s1 in
>         let (z,s3)  = baz x y s2 in ...
>
> and re-number them if I insert a new statement.
>
>

Usage of shadowing is generally bad practice. It is error-prone. Hides
obnoxious bugs like file descriptors leaks.
The correct way is to give different variables that appear in different
contexts a different name, although this is arguably less convenient and
more verbose.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130722/ec279de0/attachment.htm>


More information about the Haskell-Cafe mailing list