Open-ended list comprehension

Hello all, when I write my own recursions, I often end up with something like a : b : c : (f x) where f x returns a list. I assume this avoids the costly (++) function, right? But when I use list comprehensions I always get a complete list and it is costly to append something to it. How can I use the power of list comprehensions, but return an [a]->[a] instead of an [a]? Is this a good idea at all, or will I pile up thunks?

Hi martin,
Check dlist (https://hackage.haskell.org/package/dlist-0.7.1.1).
On Wed, Mar 25, 2015 at 11:21 PM, martin
Hello all,
when I write my own recursions, I often end up with something like
a : b : c : (f x)
where f x returns a list. I assume this avoids the costly (++) function, right?
But when I use list comprehensions I always get a complete list and it is costly to append something to it. How can I use the power of list comprehensions, but return an [a]->[a] instead of an [a]?
Is this a good idea at all, or will I pile up thunks?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Am 03/25/2015 um 07:00 PM schrieb divyanshu ranjan:
Hi martin,
Check dlist (https://hackage.haskell.org/package/dlist-0.7.1.1).
I cannot see how I can create a dlist via a list comprehension, other than running fromList. But I assume this already has o(n) complexity. It may pay after several appends, though. What I am looking for is, if I have: veryLongList = [x | x <- ...] how can I use list a comprehension and end up with a dlist?
On Wed, Mar 25, 2015 at 11:21 PM, martin
mailto:martin.drautzburg@web.de> wrote: Hello all,
when I write my own recursions, I often end up with something like
a : b : c : (f x)
where f x returns a list. I assume this avoids the costly (++) function, right?
But when I use list comprehensions I always get a complete list and it is costly to append something to it. How can I use the power of list comprehensions, but return an [a]->[a] instead of an [a]?
Is this a good idea at all, or will I pile up thunks?
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Hello, DList is a monad, so you can use them like lists with the MonadComprehensions extension. Alternatively, make use of the MonadPlus functions, which give you the same power without the nice syntax. Best regards, Marcin MRotek
participants (3)
-
divyanshu ranjan
-
Marcin Mrotek
-
martin