[Haskell-cafe] Polymorphic algebraic type constructors

Adrian Hey ahey at iee.org
Wed Jun 23 13:54:43 EDT 2004

On Wednesday 23 Jun 2004 2:08 pm, MR K P SCHUPKE wrote:
> If I want a let binding I can write one.

The trouble with this is that a sub-optimal (I don't like to use
the word "naive") implementation will actually create a new heap
construction, rather than re-use the one it knows (or should know)
it already has (as a result of pattern matching). This probably
isn't a problem with zero arity constructors like [] which AFAIK
are universally shared anyway in GHC (and probably other Haskell

Example, if instead of..
 f v@(Left s) = <expr>
a programmer has to write..
 f   (Left s) = let v=Left s in <expr>

Of course there's no reason in principle why a reasonably smart
compiler should optimise out the unnecessary construction AFAICS,
and I think last time this was discussed there was talk of doing this
with ghc. Dunno if it does though, or about other Haskell implementations.

The programmer could help out the less smart compilers a bit by using
"as patterns", if it wasn't for the fact that this often results in a
type error.

Adrian Hey

More information about the Haskell-Cafe mailing list