[clean-list] translation of Haskell newtype?
Brian Rogoff
bpr@artisan.com
Wed, 31 Jul 2002 12:03:27 -0700
John van Groningen writes:
> Brian Rogoff wrote:
> > [... how to translate Haskell's newtype into Clean? ..]
> The Clean compiler does not optimise this special case (a type with a
> single strict unary constructor). However the compiler attempts to optimise
> a record with a single (strict) field, by unboxing such a record if it
> appears as a strict field in (another) record, or as a strict argument of
> a constructor.
> Strict arguments and results of functions are also unboxed for records.
>
> So it is better to translate newtype into a record with a strict field,
> instead of a constructor.
>
> If you prefer to use a constructor like syntax, you could use a macro:
>
> NewType a :== {new_type=a}
Thanks, that's a help. I take it that this won't work then if I want to
create new unboxed Integer or Real types which can be used in unboxed
arrays?
Also, I find that some of the "Haskell" code I want to translate uses
multi-parameter type classes with functional dependencies. Is there a
workaround there too? If not, will we see them (or some similar
functionality) in a future Clean? I'm not whining much yet, since I
don't real programming experience with this feature, I'm just playing with
some ideas from Haskell papers and I want to translate them to Clean,
however fundeps look like a really useful feature if you have MPTC.
Thanks again!
-- Brian