What is the “let” keyword in functional languages like F# and OCaml for?

前端 未结 6 1419
一向
一向 2020-12-20 11:51

When looking at F#, Ocaml and other functional language code examples I notice that the let keyword is used very often.

  • Why do you need it? Why were the langua
6条回答
  •  天命终不由人
    2020-12-20 12:28

    In Haskell,

    foo = let x = 5
          y = 7
          in z=x+y
    

    is used to make clear that x and y are "private" variables to foo.

提交回复
热议问题