我是Haskell的新手。 我在这里有一个问题。我可以像这样的守卫做任务
task2 x "Celsius"
| x>=20 = "It is Hot"
| x<= (-5) = "It is very cold"
| x<=10 = "It is cold"
| x<20 = "It is warm"
如何使用案例功能来完成这项任务?
喜欢
案例x&#34; Celsius&#34; = x的情况x&gt; = 20,但它不起作用。
答案 0 :(得分:3)
您可以将警卫放入case
这样的表达式中:
case some_expression of
x | x>=20 -> "It is Hot"
| x<= (-5) -> "It is very cold"
....