[clean-list] About abstract synonym types...

John van Groningen johnvg@cs.kun.nl
Thu, 5 Feb 2004 12:53:15 +0100


>On 04-Feb-2004, Fabien TODESCATO <fabien.todescato@wanadoo.fr> wrote:
> > The Clean home pages advertises the new 2.1 version as featuring
> > "abstract synonym types". I couldn't however find any explanations nor
> > any syntax definition in the relese 2.1 of the language report that
> > ships with the system.

This is not yet explained in the language report.

Fergus Henderson wrote:
>I'm guessing that an "abstract synonym type" would be an abstract type
>that is defined as a synonym type.  An abstract type is one whose
>name is exported to other modules.

Yes, an abstract type is a type whose name is exported, but not the
definition. This has always been possible in Clean for types and synonym types.
Because the implementation of the type is hidden, values of this type are
always boxed outside the module in which they are defined.

To prevent boxing and unboxing, in Clean 2.1 it is now possible
to expose the implementation only to the code generator of the compiler,
by writing the definition between ( ) in the definition module. For example:

:: MyInt (:== Int);

instead of

:: MyInt;

for an abstract type, or

:: MyInt :== Int;

for a synonym type.

In this way the implementation of the type can be hidden without loss of
efficiency, by expanding these abstract type synonyms before generating
code.

> > Is this "abstract synonym types facility" the equivalent of the
>> "newtype" construction in Haskell ?
>
>If my guess is right, then no, the two are not really equivalent.
>The difference is that with Haskell's newtype, conversions between the
>abstract type and its definition must be explicit.

In Clean conversions between the abstract type and its definition must
be done in the module in which the abstract type is defined.

> > And if so, are recursive type definitions supported ?
>
>I think the answer to that is probably no, because IIRC Clean does
>not support recursive synonym types.

That is correct.

>I have my own questions about abstract synonym types in Clean 2.1:
>
>	- how do they interact with type classes?

Abstract types are supported. For example, instances for abstract types
can be defined.

>	- how do they interact with separate compilation?
>	  Does changing the definition of an abstact synonym type
>	  require recompiling modules that import the module which
>	  defines it?

Not for abstract types, only for the new 'abstract synonym types'.

>	- has the Clean team considered how abstract synonym types
>	  should be supported if compiling to a strongly-typed target
>	  language that does not support abstract synonym types,
>	  such as C++, Java, the JVM, or the .NET CLR?

No, but I don't think there would be any problems for the new 'abstract
synonym types' because code is generated in the same way as for
ordinary synonym types.

Regards,

John van Groningen