
ok, now I did it by just calling from the original function by to a new one with an empty list at the beginning. How can I add the date at the end of the list? By creating a new list from the new date and using concat or is there a simpler way? -------- Original-Nachricht --------
Datum: Fri, 12 Feb 2010 23:18:06 +0100 Von: Daniel Fischer
An: kane96@gmx.de CC: beginners@haskell.org Betreff: Re: [Haskell-beginners] consing an element to a list inside a file
Am Freitag 12 Februar 2010 20:15:26 schrieb kane96@gmx.de:
the exercise looks like that:
readMyCal :: IO MyCalendar readMyCal = do putStr "day: " d <- readInt putStr "month: " m <- readMonth putStr "year: " y <- readInt let mydate = (d,m,y) if not (legalDate mydate) then do putStrLn "wrong" --COMPLETE-1-- else --COMPLETE-2--
COMPLETE-1: the user can give in a new date. I did it by simple calling the function again
Reasonable.
COMPLETE-2: the user can choose if he wants to enter a new. If not, all dates the user has put in should be put out as a calendar (a list of dates)
Okay, that's not nice. But since you have no global variables to store the list of dates entered in (yes, there are ways to have global variables, but it's not a good idea unless you really have to), call
readMoreDates :: [MyDate] -> IO MyCaledar readMoreDates previous = do ...
(code duplication where it isn't really necessary, but what the heck).
-- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01