Nestable type definitions #401

Open
jckarter opened this Issue Oct 9, 2012 · 2 comments

Comments

Projects
None yet
1 participant
Owner

jckarter commented Oct 9, 2012

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

ghost commented Nov 19, 2012

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?

Owner

jckarter commented Nov 19, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment