[Haskell-beginners] print all days of calendar

Chaddaï Fouché chaddai.fouche at gmail.com
Sat Dec 19 05:16:45 EST 2009


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ï


More information about the Beginners mailing list