[Haskell-beginners] find element of tupels

kane96 at gmx.de kane96 at gmx.de
Fri Dec 18 09:57:56 EST 2009


thx Daniel. Now I implemented it like that to use my monthAndMaxDay list and just use the isLeapYear check for February:

legalDate :: Date -> Bool
legalDate (myDay, Feb, myYear) = 0 < myDay && myDay <= (if isLeapYear        
    myYear then 29 else 28)
legalDate (myDay, myMonth, myYear) = maybe False id $ do
    days <- lookup myMonth monthAndMaxDay
    return (not (myDay <= 0) && (myDay <= days))


-------- Original-Nachricht --------
> Datum: Fri, 18 Dec 2009 00:17:56 +0100
> Von: Daniel Fischer <daniel.is.fischer at web.de>
> An: beginners at haskell.org
> Betreff: Re: [Haskell-beginners] find element of tupels

> Am Donnerstag 17 Dezember 2009 20:44:34 schrieb Henk-Jan van Tuyl:
> > On Thu, 17 Dec 2009 17:18:41 +0100, <kane96 at gmx.de> wrote:
> > > thanks Magnus, great, works so far. I added to check that myDay have
> to
> > > be greater 0:
> > >
> > > legalDate :: Date -> Bool
> > > legalDate (myDay, myMonth, myYear) = maybe False id $ do
> > >     days <- lookup myMonth monthAndMaxDay
> > >     return (not (myDay <= 0) && (myDay <= days))
> > >
> > > Another thing is, that I have to check for leapYears. I have a
> function
> > > that checks if a year is a leap year
> > >
> > > isLeapYear :: Int -> Bool
> > > isLeapYear year = mod year 4 == 0
> >
> > That is not entirely correct; from package time:
> >    isLeapYear :: Integer -> Bool
> >    isLeapYear year = (mod year 4 == 0) && ((mod year 400 == 0) || not
> (mod
> > year 100 == 0))
> >
> > > monthAndMaxDay has 30 days for February which have to be fix. So i
> have
> > > to check in legalDate if the year is a leap year. If so I have to
> check
> > > myDay in February for 29 days, otherwise for 28 days. How can I
> > > implement this to isLegalDate?
> >
> > Use fromGregorianValid from package time.
> 
> Or
> 
> legalDate (d,Feb,y) = 0 < d && d < (if isLeapYear y then 30 else 29)
> legalDate (d,m,y)
>     | m `elem` [Apr,Jun,Sep,Nov] = 0 < d && d < 31
>     | otherwise = 0 < d && d < 32
> 
> >
> > Regards,
> > Henk-Jan van Tuyl
> >
> >
> > --
> > http://Van.Tuyl.eu/
> > http://members.chello.nl/hjgtuyl/tourdemonad.html
> > --
> 
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01


More information about the Beginners mailing list