Algebraic types and subclassing

Nick Kallen phantom@earthlink.net
Thu, 12 Mar 1998 15:13:09 -0800


>>Add :: Int Int -> Int
>>Add = (+)
>>
>>Doesn't work, although I think it ought to.
>
>Why not write "Add :: (Int -> Int -> Int); Add = (+)" ?
>Then the type doesn't look so nice, but the definition does.


One can very well do that. But it's annoying. Moreover, this solution of
adding parentheses doesn't work with the parser example (you need to take
away [effective] parentheses, which is impossible!) Lastly, the operator
equivalence thing I demonstrated was impossible. I'm proposing that this
(seemingly) trivial and insignificant change in the syntax of Clean would
make the language noticably more convenient.

>>>It is possible to hide types using the module structure of Clean
(exporting
>>the type >constructor, but not its definition.
>Again, this can be done by using Clean's module system:
>--------------
>definition module RGB
>
>:: RGB // Note: the implementation is not revealed
>
>makeRGB :: Int Int Int -> RGB // The "constructor"
>
>-------------
>
>implementation module RGB
>
>import StdEnv
>
>:: RGB = { red :: Int, green :: Int, blue :: Int }

Wow, I didn't know you could do this! So, scratch my request for
language-level support of ADTs. :)