# HG changeset patch # User Adam Chlipala # Date 1318687513 14400 # Node ID 644558d9c756c2b54a6db6a7878fc215e15e6fb0 # Parent 34364e383bed89e6670701df3aded756a8a092e8 Extend and document 'con' syntax with arguments diff -r 34364e383bed -r 644558d9c756 doc/manual.tex --- a/doc/manual.tex Sat Oct 15 09:04:41 2011 -0400 +++ b/doc/manual.tex Sat Oct 15 10:05:13 2011 -0400 @@ -380,7 +380,7 @@ &&& \{\kappa\} & \textrm{type-level records} \\ &&& (\kappa\times^+) & \textrm{type-level tuples} \\ &&& X & \textrm{variable} \\ - &&& X \longrightarrow k & \textrm{kind-polymorphic type-level function} \\ + &&& X \longrightarrow \kappa & \textrm{kind-polymorphic type-level function} \\ &&& \_\_ & \textrm{wildcard} \\ &&& (\kappa) & \textrm{explicit precedence} \\ \end{array}$$ @@ -549,6 +549,8 @@ In general, several adjacent $\lambda$ forms may be combined into one, and kind and type annotations may be omitted, in which case they are implicitly included as wildcards. More formally, for constructor-level abstractions, we can define a new non-terminal $b ::= x \mid (x :: \kappa) \mid X$ and allow composite abstractions of the form $\lambda b^+ \Rightarrow c$, elaborating into the obvious sequence of one core $\lambda$ per element of $b^+$. +Further, the signature item or declaration syntax $\mt{con} \; x \; b^+ = c$ is shorthand for wrapping of the appropriate $\lambda$s around the righthand side $c$. The $b$ elements may not include $X$, and there may also be an optional $:: \kappa$ before the $=$. + In some contexts, the parser isn't happy with token sequences like $x :: \_$, to indicate a constructor variable of wildcard kind. In such cases, write the second two tokens as $::\hspace{-.05in}\_$, with no intervening spaces. Analogous syntax $:::\hspace{-.05in}\_$ is available for implicit constructor arguments. For any signature item or declaration that defines some entity to be equal to $A$ with classification annotation $B$ (e.g., $\mt{val} \; x : B = A$), $B$ and the preceding colon (or similar punctuation) may be omitted, in which case it is filled in as a wildcard. diff -r 34364e383bed -r 644558d9c756 src/urweb.grm --- a/src/urweb.grm Sat Oct 15 09:04:41 2011 -0400 +++ b/src/urweb.grm Sat Oct 15 10:05:13 2011 -0400 @@ -706,8 +706,14 @@ sgi : CON SYMBOL DCOLON kind ((SgiConAbs (SYMBOL, kind), s (CONleft, kindright))) | LTYPE SYMBOL ((SgiConAbs (SYMBOL, (KType, s (LTYPEleft, SYMBOLright))), s (LTYPEleft, SYMBOLright))) - | CON SYMBOL EQ cexp ((SgiCon (SYMBOL, NONE, cexp), s (CONleft, cexpright))) - | CON SYMBOL DCOLON kind EQ cexp ((SgiCon (SYMBOL, SOME kind, cexp), s (CONleft, cexpright))) + | CON SYMBOL cargl2 kopt EQ cexp (let + val loc = s (CONleft, cexpright) + + val k = Option.getOpt (kopt, (KWild, loc)) + val (c, k) = cargl2 (cexp, k) + in + (SgiCon (SYMBOL, SOME k, c), loc) + end) | LTYPE SYMBOL EQ cexp ((SgiCon (SYMBOL, SOME (KType, s (LTYPEleft, cexpright)), cexp), s (LTYPEleft, cexpright))) | DATATYPE dtypes ((SgiDatatype dtypes, s (DATATYPEleft, dtypesright))) diff -r 34364e383bed -r 644558d9c756 tests/conargs.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/conargs.ur Sat Oct 15 10:05:13 2011 -0400 @@ -0,0 +1,9 @@ +con func a b = a -> b + +signature S = sig + con funcy a b = a -> b +end + +structure M : S = struct + con funcy = func +end