Is there a lazy functional (immutable) language where functions have intermediate variables+return?

67 views Asked by At

I apologize if this has an obvious answer. I would like to find a lazy functional programming language where the following pseudo code makes sense:

let f = function(x) {
    let y = x*x  // The variables y and z
    let z = y*2  // are local
    return z
}
1

There are 1 answers

0
djh On BEST ANSWER

This is, of course, doable in a functional, declarative language like haskell. Either with let bindings or where keyword. These are just chained together in one expression.

--local variables with 'where'

f :: Int -> Int
f x = z where
  z = y*2
  y = x*x

--local variables with let

g :: Int -> Int
g x =
   let y = x*x
       z = y*2
     in z

https://wiki.haskell.org/Let_vs._Where