[Haskell-cafe] Re: Eta-expansion and existentials (or: types destroy my laziness)

Max Bolingbroke batterseapower at hotmail.com
Tue Oct 19 06:16:16 EDT 2010


Hi Oleg,

Thanks for your reply!

> Really? Here are two 'cons' that seem to satisfy all the criteria

Thanks - your definitions are similar to Roman's suggestion.
Unfortunately my criteria 3) is not quite what I actually wanted - I
really wanted something "GHC-optimisable" - (so non-recursive
definitions are a necessary but not sufficient condition).

The problem is that I'd like to do the static argument transformation
on the "Stream" argument to "cons" so that GHC can optimise it
properly. This is why I've made my "cons" pattern match on str
directly, so the local "run"/"step" loop can refer to the lexically
bound step/state fields of the stream being consed on to.

As Roman suggests, the best way to get GHC to optimise these
compositions would be to do something like extend GHC so it can do the
SAT by itself :-). Alternatively, a type-safe eta for data types
involving existentials would let me do what I want without GHC changes
- but I don't think there is a way to define this.

>        Finally, if one doesn't like existentials, one can try
> universals:
>        http://okmij.org/ftp/Algorithms.html#zip-folds
>        http://okmij.org/ftp/Haskell/zip-folds.lhs

I hadn't seen this - thanks! It is certainly a neat trick. I can't
quite see how to use it to eliminate the existential I'm actually
interested eta-expanding without causing work duplication, but I'll
keep thinking about it.

Cheers,
Max


More information about the Haskell-Cafe mailing list