Baalthazaq
08-16-2004, 11:17 AM
Just wondering if there is an easy way of doing this in Haskell. Just fewer lines:
I have two data types, and some other functions which are immaterial to the actual question.
The following are all the parts that work:
> data Day = Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday deriving (Show, Eq)
> data Weather = Overcast | Wind | Rain | Snow | Sun | Cold deriving (Show, Eq)
> typical :: Day -> Weather -> Bool
> typical _ Cold = True
> typical a Snow = is_weekend a
> typical a Sun = is_weekend a
> typical _ _ = False
Now, above the >typical _ _ = False line there is a line I've missed.
What I WANT to write is something along the lines of:
>typical (Sunday | Monday | Tuesday) (Overcast | Wind) = True
Instead I've opted for writing each case out independantly because I couldn't get Haskell to compile either this, or any of the other variants of this line.
I'm sure (just because it's haskell, and it's lovely like that most of the time), that I'm just doing something minorly wrong.
I have two data types, and some other functions which are immaterial to the actual question.
The following are all the parts that work:
> data Day = Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday deriving (Show, Eq)
> data Weather = Overcast | Wind | Rain | Snow | Sun | Cold deriving (Show, Eq)
> typical :: Day -> Weather -> Bool
> typical _ Cold = True
> typical a Snow = is_weekend a
> typical a Sun = is_weekend a
> typical _ _ = False
Now, above the >typical _ _ = False line there is a line I've missed.
What I WANT to write is something along the lines of:
>typical (Sunday | Monday | Tuesday) (Overcast | Wind) = True
Instead I've opted for writing each case out independantly because I couldn't get Haskell to compile either this, or any of the other variants of this line.
I'm sure (just because it's haskell, and it's lovely like that most of the time), that I'm just doing something minorly wrong.