# [Haskell-beginners] print all days of calendar

kane96 at gmx.de kane96 at gmx.de
Sun Dec 20 16:11:51 EST 2009

I implemented the first step which works if I fix the months (instead of the Month Enum) and just return the day and not an element of type Date

this works:
calendar year = [ day | month <- [Jan, Feb], day <- [1..31], legalDate(day,month,year)     == True ]

this doesn't work:
calendar year = [ Date(day,month,year) | month <- Month, day <- [1..31], legalDate(day,month,year)     == True ]

-------- Original-Nachricht --------
> Datum: Sat, 19 Dec 2009 11:16:45 +0100
> Von: "Chaddaï Fouché" <chaddai.fouche at gmail.com>
> An: kane96 at gmx.de
> CC: beginners at haskell.org
> Betreff: Re: [Haskell-beginners] print all days of calendar

> On Fri, Dec 18, 2009 at 5:01 PM,  <kane96 at gmx.de> wrote:
> > I also have a function from a previous exercise which checks if a given
> date is valid. Is there a function for a loop that iterates from 1 to n and
> checks if the date is valid. If it's valid it should return the date
> otherwise it should jump to the next month or end at the end of the year? Or is
> it better to do it on another way with this data I have?
>
> Since you derived Enum for Month, you can do [Jan..Dec] and get the
> list of the months in order. There are then two options, either you
> generate all cartesian product of [Jan..Dec] and [1..31] and check
> which are valid, or you write a function that for a given month and
> year tells you how many days it counts and then generate for month "m"
> all the pair in combination with [1..daysCount m].
>
> Whatever your decision, list comprehensions are probably the tool of
> choice to do it though it is by no mean harder to do without.
>
> --
> Jedaï

--
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