[Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]
Alberto G. Corona
agocorona at gmail.com
Wed Jul 10 10:58:39 CEST 2013
I think that a non-non recursive let could be not compatible with the pure
nature of Haskell.
Let is "recursive" because, unlike in the case of other
languages, variables are not locations for storing values, but the
expressions on the right side of the equality themselves. And obviously it
is not possible for a variable-expression to be two expressions at the same
time. The recursiveness is buildt-in. It comes from its pure nature.
For a non recursive version of let, it would be necessary to create a new
closure on each line, to create a new variable-expression with the same
name, but within the new closure. A different variable after all. That is
what the example with the Identity (and the state monad) does.
So I think that the ugly return example or the more elegant state monad
alternative is the right thing to do.
2013/7/10 Ertugrul Söylemez <es at ertes.de>
> oleg at okmij.org wrote:
>
> > Hear, hear! 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 ...
>
> This isn't a case for non-recursive let. It is one of the rare cases
> where you might actually consider using a state monad.
>
>
> Greets,
> Ertugrul
>
> --
> Not to be or to be and (not to be or to be and (not to be or to be and
> (not to be or to be and ... that is the list monad.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
--
Alberto.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130710/641d6b58/attachment.htm>
More information about the Haskell-Cafe
mailing list