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

Daniel Fischer daniel.is.fischer at web.de
Thu Feb 11 16:54:59 EST 2010


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)



More information about the Beginners mailing list