[clean-list] Synonym types
Arjen van Weelden
arjenw@cs.kun.nl
Fri, 03 Oct 2003 10:48:51 +0200
Alan Hutchinson wrote:
> Hello Arjen
> Thanks for your mail.
> It helps understand the matter, though I am still not sure
> what to do about it.
Hello Alan,
If you want to use types in such a way, you will have to use algebraic
or record types in Clean. Clean does not support something like
Haskell's newtype.
You could try using a algebraic type or a record type. The record type
run-time representation is similar to tuples.
:: SynTypeA a b = {fst :: a, snd :: b}
:: Constr t1 t2 a b = C (t1 a b) (t2 a b)
:: SynTypeB a b :== Constr SynTypeA SynTypeA a b
testFn :: SynTypeA Int String
testFn = {fst = 3, snd = "It works."}
Start = (fst, snd) where {fst, snd} = testFn
To simulate Haskell's newtype, because Clean does not (fully) support
class instances for synonym types, you can also use a record with a
single field. This is more efficient than an algebraic constructor.
Unfortunately, it does require more syntax.
regards,
Arjen