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

Henning Thielemann schlepptop at henning-thielemann.de
Sun Oct 24 12:43:48 EDT 2010

Max Bolingbroke schrieb:

> Let's start with a simple example of an existential data type:
>> data Stream a = forall s. Stream s (s -> Maybe (a, s))

I use quite the same data type for my signal processing applications:

You may be interested in my overview:

> Now we may wish to define infinite streams using value recursion:
>> ones :: Stream Int
>> ones = cons 1 ones

For me a Stream is a List without storage, thus in your example you
cannot share the content of 'ones'. The internal state type becomes
larger and larger for every new element (every element adds a new layer
of Maybe, if I'm not mistaken).

In cases, where I want this kind of recursion I store the content
generated by a Stream in a list or another more efficient stream type or
I write special functions for this purpose (e.g., 'repeat' in the case
of 'ones').

More information about the Haskell-Cafe mailing list