Haskell: Where vs. Let

前端 未结 5 1676
余生分开走
余生分开走 2020-12-02 04:56

I am new to Haskell and I am very confused by Where vs. Let. They both seem to provide a similar purpose. I have read a few comparisons bet

5条回答
  •  伪装坚强ぢ
    2020-12-02 05:24

    I found this example from LYHFGG helpful:

    ghci> 4 * (let a = 9 in a + 1) + 2  
    42  
    

    let is an expression so you can put a let anywhere(!) where expressions can go.

    In other words, in the example above it is not possible to use where to simply replace let (without perhaps using some more verbose case expression combined with where).

提交回复
热议问题