局部声明
在表达式中声明
局部值仅在作用域内可见
使用缩进来表示作用域
let
f x =
let y = x * x
-- 可以写多行,let不重复写
in y + 2
f x =
let y :: Int
y = x * x
{- n :: Int
n = 2 -}
in y + 2
where
f x = y + 2
where y = x * x
-- 可以写多行,where不重复写
f x = y + 2
where y :: Int
y = x * x
{- n :: Int
n = 2 -}
y = myf x
示例
f x = y + 2
where
myf :: Int -> Int
myf n =
let p = 1
in n + p
y = myf x