【发布时间】:2012-04-01 01:21:53
【问题描述】:
我知道它们不能跨越模式匹配(即您需要为每个模式重写 'where' 子句),但范围界定如何对守卫起作用?
例如这行得通吗?
myFunction x1 x2
| x1 > x2 = addOne x1
| x1 < x2 = addOne x2
| otherwise = x1
where addOne = (1+)
还是应该这样?
myFunction x1 x2
| x1 > x2 = addOne x1
where addOne = (1+)
| x1 < x2 = addOne x2
where addOne = (1+)
| otherwise = x1
【问题讨论】:
标签: haskell scope pattern-matching where-clause