[clean-list] About abstract synonym types...
Arjen van Weelden
arjenw@cs.kun.nl
Thu, 05 Feb 2004 13:01:08 +0100
Fergus Henderson wrote:
> 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.
>
>
> 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.
>
>
>>Is this "abstract synonym types facility" the equivalent of the
>>"newtype" construction in Haskell ?
No. It is an abstract type in the eyes of the programmer, the compiler
knows the concreet implementation of the type and can perform certain
optimisations. However, the compiler will not allow the programmer to
make use of the knowledge of the implementation of the type. So, no
unboxed arrays of this type are allowed (even if it is an synonym for a
basic type), and no value denotation can have the semi-abstract type
(even if it is just an Int).
Normal abstract type are equivalent with there semi-abstract types,
except that some part of the compiler knows the implementation of the
type, which will not let the programmer use that information.
>
> 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.
>
>
>>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.
Indeed.
Semi-abstract (non-synonym) types might be implemented at some time in
the future, which would support recursion. But knowing the
implementation of normal/non-synonym types usually does not provide more
optimization opportunities.
>
> I have my own questions about abstract synonym types in Clean 2.1:
>
> - how do they interact with type classes?
They are abstract types, so another module can define instances on that
type, but it cannot make use of the type implementation.
Knowing the concreet type does not allow you to use instances of the
concreet type on it.
>
> - 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?
They should not force compilation of other modules, but because the
semi-abstract definition is in the .dcl definition module, it will
trigger recompilation.
>
> - 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?
I don't know, but the types are abstract and can therefore not be
transfered between languages without explicit user marshalling code.
regards,
Arjen