clay icon indicating copy to clipboard operation
clay copied to clipboard

Nestable type definitions

Open jckarter opened this issue 13 years ago • 2 comments

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);

jckarter avatar Oct 09 '12 19:10 jckarter

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?

ghost avatar Nov 19 '12 23:11 ghost

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.

jckarter avatar Nov 19 '12 23:11 jckarter