[clean-list] ADTs for fields in record types, please!

Fergus Henderson fjh@cs.mu.OZ.AU
Mon, 13 Oct 2003 13:39:29 +1000


On 11-Oct-2003, Robin Green <greenrd@greenrd.org> wrote:
> One important thing that I find lacking in Clean 2.0, and which
> I hope will be addressed in a future release, is proper support
> for Abstract Data Types (ADTs) (aka interfaces in Java).
...
> It should be possible, in *any* context where a type needs to be
> specified, to specify by some means an Abstract Data Type, so
> that one or more functions is defined on this abstract type,
> but the actual implementation of the type (in terms of how it
> is represented and how the function(s) is/are implemented)
> can be freely varied on an instance-by-instance basis. "Freely"
> in the sense that the postcondition(s) of the function(s)
> should be adhered to, but the choice of representation should
> be entirely open.
> 
> The best way to do that in Clean 2.0 seems to be to say
> something like
> 
> myfunction::a -> Foo | ADT a
> 
> But it is not possible to use the "| ADT a" syntax when
> defining the type of a field in a record type definition,
> for example.
...
> Will this be fixed in a future release? Or is there some
> alternative way of doing what I want to do that I've missed?

In Glasgow Haskell and Mercury, which both have quite similar
type systems to Clean, the solution is to use existential types
with type class constraints.

In Glasgow Haskell, the syntax for existential types with type
class constraints is like this:

	data MyType = forall a . ADT a => MyConstructor a

In Mercury, it is

	:- type my_type ---> some [A] my_constructor(A) => adt(A).

Clean does supports existential types, e.g.

	:: MyType = E.a: MyConstructor a

and as you noted above, Clean supports type class constraints.
But I don't know if Clean supports existential types with type class
constraints, or what the syntax for them would be in Clean.
The Clean 2.0 Report (draft) on the Clean web page doesn't specify
any syntax for it, AFAICT, so perhaps it is not supported.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.