Haskell:如何使用案例功能

时间:2014-01-25 14:11:44

标签: haskell case

我是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,但它不起作用。

1 个答案:

答案 0 :(得分:3)

您可以将警卫放入case这样的表达式中:

case some_expression of
    x | x>=20 -> "It is Hot"
      | x<= (-5) -> "It is very cold"
      ....