On 25-Feb-1999, Lennart Augustsson <[EMAIL PROTECTED]> wrote:
> 
> [someone wrote:]
> > I've lost track of what we're talking about here.  In what system can
> > we not hope for principal types?
>
> [...] Cayenne doesn't have that property.
> Again, I think this is a feature, not a bug.  I'll include
> a small example below.
...
> struct 
>    abstract
>    type Stack a = List a
> 
>    push :: a -> Stack a -> Stack a
>    push x xs = x : xs
> 
>    ...
> 
> This has type
> sig
>    type Stack a
>    push :: a -> Stack a -> Stack a
>    ...
> 
> Outside the defining struct Stack is abstract and cannot be
> interchanged for List.
> 
> But here's another type we could give push
> 
>    push :: a -> List a -> Stack
> 
> which (outside the defining struct) would look like a totally
> different creature.

So what does Cayenne do if you don't declare the type for `push'? 
Does it report an error?

I agree that allowing this kind of thing is a feature, not a bug,
so long as the compiler reports an error rather than inferring
some (non-principle) type for cases like that where there is no
principle type.

The same issue with regard to principle types arises in Mercury with
regard to the module system, since the Mercury module system allows
synonym types to be exported as abstract types.  Mercury sidesteps this
by requiring explicit type declarations for any exported procedures.
The original rationale for this requirement was that using explicit
type declarations on interfaces is simply good software engineering
practice, and that the presence of this requirement simplifies the
implementation.  I wasn't aware that this requirement is also essential
for ensuring the existence of principle types.

Haskell's module system of course does not allow synonym types to be
exported as abstract types -- you have to use a newtype instead.
However, this may be better than Mercury's approach, because abstract
synonym types become second-class citizens once you add typeclasses,
since (in both Haskell and Mercury) you're not allowed to have instance
declarations for synonym types.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger [EMAIL PROTECTED]        |     -- leaked Microsoft memo.



Reply via email to