[Haskell-cafe] List comparisons and permutation group code
Nils Anders Danielsson
nad at cs.chalmers.se
Thu Oct 19 16:44:57 EDT 2006
On Thu, 19 Oct 2006, Tomasz Zielonka <tomasz.zielonka at gmail.com> wrote:
> On Thu, Oct 19, 2006 at 01:37:16PM -0400, Cale Gibbard wrote:
>> In order to determine if [1..length xs] has an element at all, you
>> have to evaluate length xs, which involves forcing the entire spine of
>> xs, because integers can't be partially evaluated. Computing lengths
>> of lists is a great way to introduce strictness.
> Right, so if Ints were represented as a datatype with Succ and Zero
> constructors (so integers could be partially evaluated), then the
> version with length would behave nicely on large and infinite lists :-)
Using genericLength for unary, lazy natural numbers can be convenient
for other tasks as well, for instance choosing the shorter of two
lists in a simple and lazy way.
See "Modular Lazy Search for Constraint Satisfaction Problems", Nordin
and Tolmach, http://web.cecs.pdx.edu/~apt/, around page 25, for
another (related) example.
More information about the Haskell-Cafe