[Ur] Deriving show instances

Adam Chlipala adamc at impredicative.com
Wed Oct 12 07:48:22 EDT 2011


Ron de Bruijn wrote:
> I would even prefer to have everything which can be be derived to be 
> automatically there unless a manual instance is specified.
>
> So,
>
> I would like that
>
> datatype Foo a = Foo of a
>
> val y = show (Foo 1)
>
> compiles and does what is obviously intended unless another Foo 
> specific show instance has been defined.

Again, this strikes me as much less of an issue in practice than in 
theory.  There is a real cost in language semantics complexity to adding 
such functionality, and it doesn't seem hard to get by without.  Also 
again, I would consider a patch adding this functionality.

> Completely unrelated: opalang.org doesn't appear to have actual 
> datatypes. Or rather they have disjoint sums of record types to make 
> the language more uniform. Is there any particular reason that this 
> isn't done in Ur/Web? It seems that their approach is more sensible in 
> a language with row variables.

Ur/Web supports this, too, with the [variant] type family.  You could 
even get recursive variants with shallow use of single-constructor 
datatypes.  So, you can choose which version you want!  You'll generally 
get better error messages with a built-in datatype mechanism.  Built-in 
pattern-matching notation is generally more fun to work with.



More information about the Ur mailing list