[Haskell-beginners] consing an element to a list inside a file

kane96 at gmx.de kane96 at gmx.de
Fri Feb 12 14:15:26 EST 2010


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


-------- Original-Nachricht --------
> Datum: Thu, 11 Feb 2010 23:30:05 +0100
> Von: Daniel Fischer <daniel.is.fischer at web.de>
> An: kane96 at gmx.de
> CC: beginners at haskell.org
> Betreff: Re: [Haskell-beginners] consing an element to a list inside a file

> Am Donnerstag 11 Februar 2010 23:04:01 schrieb kane96 at gmx.de:
> > but the exercise was nearly complete on the sheet and I just have to
> > complete two parts and one of them is to ask the user if he want's to do
> > more input. If so, I have to let him input a new value (triple) for
> > MyDatatype, otherwise I have to print the list with all triples
> >
> 
> But to print it, you need to have a reference to the list of inputs. The 
> easiest way is to have it as a parameter in the worker loop.
> 
> What *exactly* is your task? What is given and what are the specifications
> for a solution?
> 
> > >
> > > Am Donnerstag 11 Februar 2010 22:34:45 schrieb kane96 at gmx.de:
> > > > the problem is the function should be
> > > > readMyDatatype :: IO MyDatatype
> > > > readMyDatatype = do ...
> > > > Is it possible to do it somehow different without a parameter?
> > >
> > > Separate the worker from the API function.
> > >
> > > API:
> > >
> > > readMyDatatype :: IO MyDatatype
> > > readMyDatatype = call worker with appropriate arguments
> > >
> > > worker:
> > >
> > > readMD :: t1 -> t2 -> ... -> tn -> IO MyDatatype

-- 
Sicherer, schneller und einfacher. Die aktuellen Internet-Browser -
jetzt kostenlos herunterladen! http://portal.gmx.net/de/go/atbrowser


More information about the Beginners mailing list