mardi 3 novembre 2015

Haskell multiple conditions combined

I've been looking for a while now and didn't find any answers to my question. I tried to write a function that returns the days of a specific month depending on whether it is in a lap year or not. I already defined the function "lapyear" previously. My question is how can I create an If condition within another If condition ?

Thank you a lot for your answers :)

lapyear:: Int->Bool
lapyear a
    |((rem)a 400)==0 = True
    |((rem)a 100)==0 = False
    |((rem)a 4)==0 = True
    |otherwise = False

type Mes = Int
type Anyo = Int
type Dias= Int
daysAmonth:: Mes->Anyo->Dias
daysAmonth mes anyo
if lapyear anyo then do
    |or[mes==01,mes==03,mes==05,mes==07,mes==08,mes==10,mes==12] = 31
    |mes==02 = 29
    |otherwise = 30
else
    |mes==[01,03,05,07,08,10,12] = 31
    |mes==02 = 28
    |otherwise = 30

Aucun commentaire:

Enregistrer un commentaire