Xie
Xie

Reputation: 627

Haskell: how to use case function

I am a new one for 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.

Upvotes: 0

Views: 402

Answers (1)

Ganesh Sittampalam
Ganesh Sittampalam

Reputation: 29110

You can put guards into a case expression like this:

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

Upvotes: 3

Related Questions