Fantastic! Thanks, Thomas!

On Sat, Mar 7, 2015 at 3:49 PM, Thomas Bach <thbach@students.uni-mainz.de> wrote:
Jeffrey Brown <jeffbrown.the@gmail.com> writes:

> head $ Data.Set.toList S. If I do that, am I correct that Haskell will
> not try to convert all of S to a list; instead it will only convert
> one element, and then return it, and leave the rest of the list
> unevaluated?

This is how toList from Data.Set.Base is defined in containers-0.5.0:

{--------------------------------------------------------------------
  Lists
--------------------------------------------------------------------}
-- | /O(n)/. Convert the set to a list of elements. Subject to list fusion.
toList :: Set a -> [a]
toList = toAscList

-- | /O(n)/. Convert the set to an ascending list of elements. Subject to list fusion.
toAscList :: Set a -> [a]
toAscList = foldr (:) []

The buzzword you are looking for is list fusion:

http://stackoverflow.com/questions/10945429/haskell-list-fusion-where-is-it-needed

Regards

        Thomas Bach.
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners