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

kane96 at gmx.de kane96 at gmx.de
Thu Feb 11 17:04:01 EST 2010


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

-------- Original-Nachricht --------
> Datum: Thu, 11 Feb 2010 22:54:59 +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 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
> 
> >
> > -------- Original-Nachricht --------
> >
> > > Datum: Thu, 11 Feb 2010 21:41:15 +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 21:09:37 schrieb kane96 at gmx.de:
> > > > mysecondlist = 0:mylist
> > > >
> > > > that's was I was searching for, but how can I add the element to the
> > > > same list?
> > >
> > > You can't. When you add an element to a list, it's a different list.
> > >
> > > > I have to get any number of inputs from the user and at the
> > > > end, if he doesn't want to make more inputs, I have to print a list
> > > > with all the inputs he did.
> > >
> > > Make the list a parameter of the input loop.
> > >
> > > getInputs previous = do
> > >     user <- getUserInput
> > >     if endNow user
> > >       then printList previous
> > >       else getInputs (user:previous)

-- 
NEU: Mit GMX DSL über 1000,- ¿ sparen!
http://portal.gmx.net/de/go/dsl02


More information about the Beginners mailing list