[clean-list] More transformations

Ronny Wichers Schreur ronny@cs.kun.nl
Wed, 25 Oct 2000 10:12:01 +0200


Erik Zuurbier wrote:

>When Clean will have incorporated support for transformations,
>will they also be used for things like the following:
>
>check :: [a] -> Bool
>check list = (length list) > 0
>
>[ ==> ]
>
>check :: [a] -> Bool
>check [] = False
>check _ = True

As you mentioned yourself the functions are not the same. They
have different termination behaviour, but because length returns
a 32 bit signed Int they can also differ for long lists. So the
Clean compiler can't do this transformation.

The heart of the matter is that Ints are always fully evaluated.
If length were to return a result of type

    :: Nat = Zero | Succ Nat

then it wouldn't have to traverse the whole list. Deforestation
could get rid of the intermediate Nat value to obtain the check
function you want. This representation of natural numbers is of
course inefficient for most purposes.


Ronny Wichers Schreur