[Prev][Next][Index][Thread]
Why are head and tail completely sealed?
I was implementing one of the data types from Chris Okasaki's _Purely
Functional Data Structures_ when I ran across a curiousity in the
Dylan language definition, and I was wondering if the gurus could
explain it to me.
I was implementing a collection type called a <random-access-list>
that was a subclass of <sequence>. As part of the definition, I added
head and tail methods specialized on <random-access-list>. When I
tried to compile this (using Gwydion Dylan), d2c complained that
"Library foo can't define methods on sealed generic head".
I knew that <random-access-list> was disjoint from <list>, so I was
surprised. When I looked in the DRM, I saw that this was conformant
behavior -- head and tail were specified as "functions", which meant
implementations could disallow extensions.
This is a bit surprising to me, since it seems like you can get all
the type-inference and performance benefits simply by defining a
sealed domain on <list>, eg:
define sealed domain head(<list>)
This would allow the compiler to do its optimizations whenever it
knows that a variable is a list, but I (for example) would still be
able to define a head method on a disjoint type.
Is there some subtlety I'm not seeing?
Neel
Follow-Ups: