]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_notation/doc/samples.ma
snapshot
[helm.git] / helm / ocaml / cic_notation / doc / samples.ma
index d724ac4eb7a340c6821ff1af491cf3a1bf424b4d..f1f6ac9391178a8b171c5d9fd1b8b682e086a813 100644 (file)
@@ -1,3 +1,83 @@
+
+notation
+  "\langle a , b \rangle"
+for
+  @{ 'pair $a $b }.
+print \langle 1, \langle 2, 3 \rangle \rangle.
+print 'pair 1 ('pair 2 ('pair 3 4)).
+
+notation
+  "a :: b"
+for
+  @{ 'cons $a $b }.
+print 1 :: 2 :: 'ugo.
+
+notation
+  "[ hovbox (list0 a sep ; ) ]"
+for ${
+  fold right
+    @'nil
+  rec acc
+    @{ 'cons $a $acc }
+}.
+print [1;2;3;4].
+
+notation
+  "[ list1 a sep ; | b ]"
+for ${
+  if @{ 'cons $_ $_ } then
+    fold right
+      if @'nil then
+        fail
+      else if @{ 'cons $_ $_ } then
+        fail
+      else
+        b
+    rec acc
+      @{ 'cons $a $acc }
+  else
+    fail
+}.
+print 'cons 1 ('cons 2 ('cons 3 'ugo)).
+print 'cons 1 ('cons 2 ('cons 3 'nil)).
+print [1;2;3;4].
+print [1;2;3;4|5].
+
+notation "a + b" left associative for @{ 'plus $a $b }.
+print 1 + 2 + 3.
+print 1 + (2 + 3).
+
+notation
+  "'if' a 'then' b 'else' c"
+for
+  @{ 'ifthenelse $a $b $c }.
+
+TODO collezionare le keyword e aggiungerle al lexer nonche' ricordarsele per quando si rimuove la notazione.
+
+notation
+  "a \vee b"
+for
+  @{ if $a > $b then $a else $b }
+
+notation
+  "'fun' ident x \to a"
+  right associative at precedence ...
+for
+  @{ 'lambda ${ident x} $a }
+
+NOTES
+
+@a e' un'abbreviazione per @{term a}
+"x" e' un'abbreviazione per @{keyword x}
+@_ e' un'abbreviazione per @{anonymous}
+
+\x simbolo della sintassi concreta
+'x simbolo della sintassi astratta
+
+\lbrace \rbrace per le parentesi graffe al livello 1
+
+OLD SAMPLES
+
 # sample mappings level 1 <--> level 2
 
 notation \[ \TERM a ++ \OPT \NUM i \] for 'assign \TERM a ('plus \TERM a \DEFAULT \[\NUM i\] \[1\]).
@@ -6,7 +86,7 @@ print 1 ++ 2.
 notation \[ + \LIST0 \NUM a \] for \FOLD right \[ 'zero \] \LAMBDA acc \[ 'plus \NUM a \TERM acc \].
 print + 1 2 3 4.
 
-notation \[ [ \LIST0 \TERM a \SEP ; ] \] for \FOLD right \[ 'nil \] \LAMBDA acc \[ 'cons \TERM a \TERM acc \].
+notation \[ [ \HOVBOX\[ \LIST0 \TERM a \SEP ; \] ] \] for \FOLD right \[ 'nil \] \LAMBDA acc \[ 'cons \TERM a \TERM acc \].
 print [].
 print [1;2;3;4].