[Haskell-cafe] Non-recursive let [Was: GHC bug? Let with guards loops]

oleg at okmij.org oleg at okmij.org
Wed Jul 10 09:34:38 CEST 2013


Andreas wrote: 
> The greater evil is that Haskell does not have a non-recursive let.
> This is source of many non-termination bugs, including this one here.
> let should be non-recursive by default, and for recursion we could have
> the good old "let rec".

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 ...

and re-number them if I insert a new statement. BASIC comes to mind. I
tried to lobby Simon Peyton-Jones for the non-recursive let a couple
of years ago. He said, write a proposal. It's still being
written... Perhaps you might want to write it now.

In the meanwhile, there is a very ugly workaround:

    test = runIdentity $ do
     (x,s) <- return $ foo 1 []
     (y,s) <- return $ bar x s
     (z,s) <- return $ baz x y s
     return (z,s)

After all, bind is non-recursive let.





More information about the Haskell-Cafe mailing list