[Haskell-beginners] find element of tupels

kane96 kane96 at gmx.de
Thu Dec 17 10:03:59 EST 2009

I have a list of tuples: [(Jan, 31),(Feb, 28),(Mar, 31),...] called monthAndMaxDay

Date is:
type Day = Int
data Month = Jan | Feb | Mar | Apr | May | Jun | Jul | Ago | Sep | Oct | Nov | Dec deriving (Eq,Enum,Show)
type Year = Int
type Date = (Day,Month,Year)

Now I want to check if a date is legal:
legalDate :: Date -> Bool
legalDate (myDay, myMonth, myYear) =
    not (myDay <= 0) && myDay >=  (find ((== myMonth) . fst) monthAndMaxDay) . snd

the find works to search for the month in the first element of every tupel but at the end I have to check the second value of the tupel (the day) that it issn't higher than the maximal number of days in that month. Where do I have to set the "snd" correctly. Here I get the error: Couldn't match expected type `b -> c'
           against inferred type `Maybe (Month, Day)'

Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser

More information about the Beginners mailing list