jckarter / clay

The Clay programming language
http://claylabs.com/clay
Other
404 stars 34 forks source link

Nestable type definitions #401

Open jckarter opened 12 years ago

jckarter commented 12 years ago

It would be sort of convenient to be able to define variant or newtype member types in-line in a variant or newtype definition, for instance:

variant List[T] (record Nil (), record Cons[T] (car:Pointer[List[T]], cdr:T));

newtype BigMac = private record BigMacImpl (secretSauce:SecretSauce);
ghost commented 11 years ago

Is having multiple statements/definitions on one line a 'good' thing? Realistically you could only fit a couple of in-line record definitions on the same line as the top level definition before it starts to get ugly. Is there another language that uses this form successfully?

jckarter commented 11 years ago

In traditional Hindley-Milner type systems, variant members are defined in-line as part of the variant type, so the idea was to allow those sorts of definitions, like data Maybe t = Nothing | Just t, where the component tags logically make sense as part of the type. Clay's arrangement that variants are composed over independent types is somewhat unusual, but I think Scala's case classes are roughly comparable, though IIRC Scala doesn't provide a sugar to define a type with all of its subtypes.