[英]Haskell: how to use case function
I am a new one for Haskell. 我是Haskell的新手。 I have a question here. 我在这里有一个问题。 I can do the task by guards like this 我可以像这样由警卫来完成任务
task2 x "Celsius"
| x>=20 = "It is Hot"
| x<= (-5) = "It is very cold"
| x<=10 = "It is cold"
| x<20 = "It is warm"
how to use case function to do this task? 如何使用案例函数来完成此任务?
like 喜欢
case x "Celsius" = case x of x>=20, but it is not work. case x“ Celsius” = x> = 20的case x,但不起作用。
You can put guards into a case
expression like this: 您可以将警卫放入这样的case
表达式中:
case some_expression of
x | x>=20 -> "It is Hot"
| x<= (-5) -> "It is very cold"
....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.