From b81169750193dfb71fb48764619f81dbac29c37d Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Wed, 11 Jun 2014 14:22:47 -0400 Subject: let..where..end --- doc/manual.tex | 2 ++ src/urweb.grm | 1 + tests/letwhere.ur | 7 +++++++ 3 files changed, 10 insertions(+) create mode 100644 tests/letwhere.ur diff --git a/doc/manual.tex b/doc/manual.tex index 7fd135fa..4a11430b 100644 --- a/doc/manual.tex +++ b/doc/manual.tex @@ -625,6 +625,8 @@ There are infix operator syntaxes for a number of functions defined in the $\mt{ A signature item $\mt{table} \; x : c$ is shorthand for $\mt{val} \; x : \mt{Basis}.\mt{sql\_table} \; c \; []$. $\mt{view} \; x : c$ is shorthand for $\mt{val} \; x : \mt{Basis}.\mt{sql\_view} \; c$, $\mt{sequence} \; x$ is short for $\mt{val} \; x : \mt{Basis}.\mt{sql\_sequence}$. $\mt{cookie} \; x : \tau$ is shorthand for $\mt{val} \; x : \mt{Basis}.\mt{http\_cookie} \; \tau$, and $\mt{style} \; x$ is shorthand for $\mt{val} \; x : \mt{Basis}.\mt{css\_class}$. +It is possible to write a $\mt{let}$ expression with its constituents in reverse order, along the lines of Haskell's \cd{where}. An expression $\mt{let} \; e \; \mt{where} \; ed^* \; \mt{end}$ desugars to $\mt{let} \; ed^* \; \mt{in} \; e \; \mt{end}$. + \section{Static Semantics} diff --git a/src/urweb.grm b/src/urweb.grm index 157ecfac..4671569d 100644 --- a/src/urweb.grm +++ b/src/urweb.grm @@ -1456,6 +1456,7 @@ eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright)) | UNDER (EWild, s (UNDERleft, UNDERright)) | LET edecls IN eexp END (ELet (edecls, eexp), s (LETleft, ENDright)) + | LET eexp WHERE edecls END (ELet (edecls, eexp), s (LETleft, ENDright)) | LBRACK RBRACK (EVar (["Basis"], "Nil", Infer), s (LBRACKleft, RBRACKright)) diff --git a/tests/letwhere.ur b/tests/letwhere.ur new file mode 100644 index 00000000..8854f2aa --- /dev/null +++ b/tests/letwhere.ur @@ -0,0 +1,7 @@ +fun main () : transaction page = + let + return Hi {[alice]} and {[bob]}! + where + val alice = "Alice" + val bob = "Bob" + end -- cgit v1.2.3