Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
fa20d474
Commit
fa20d474
authored
Jul 10, 2007
by
Pietro Abate
Browse files
[r2003-07-29 14:33:46 by cvscast] Empty log message
Original author: cvscast Date: 2003-07-29 14:33:46+00:00
parent
87f9b98a
Changes
2
Hide whitespace changes
Inline
Side-by-side
driver/examples.ml
View file @
fa20d474
...
@@ -362,23 +362,15 @@ let [x] = bold [doc] in print_xml x;;
...
@@ -362,23 +362,15 @@ let [x] = bold [doc] in print_xml x;;
let stack = ref [Int*] []
let stack = ref [Int*] []
let fun push(x : Int) : [] =
let fun push(x : Int) : [] =
stack := [x
!
!stack]
stack := [x
;
!stack]
let fun pop ([] : []) : Int =
let fun pop ([] : []) : Int =
match !stack with [x ;y] -> stack := y; x | _ -> raise
\"
Empty stack
\"
match !stack with [x ;
y] -> stack := y; x | _ -> raise
\"
Empty stack
\"
(* In a pattern [ ... ; y] the variable y captures the tail of the *)
(* In [ pattern ;y] the variable y captures the rest of the *)
(* sequence. It is equivalent to [ ... y::_*]. *)
(* sequence. It is equivalent to [pattern y::_*] *)
(* In an expression [ ... ; e ] the expression e denotes the tail *)
(* *)
(* of the sequence. It is equivalent to [ ... ] @ e *)
(* Since sequences are encoded by pairs, we could write *)
(* the following [deprecated] equivalent definitions *)
(*
let fun push(x : Int) : [] =
stack := (x, !stack)
let fun pop ([] : []) : Int =
match !stack with (x, y) -> stack := y; x | _ -> raise
\"
Empty stack
\"
*)
;;
;;
...
...
web/examples/reference.cd
View file @
fa20d474
(* In CDuce the expression "ref T exp" returns a reference *)
(* In CDuce the expression "ref T exp" returns a reference *)
(* to the result of "exp" and has type "ref T" provided that *)
(* to the result of "exp" and has type "ref T" provided that *)
(* "exp" is of type "T" *)
(* "exp" is of type "T". References come equipped with three *)
(* operators: ":=" (assignment), "!" (dereferencing), and ";"*)
(* (sequencing). *)
let stack = ref [Int*] []
(* References come equipped with three operators: ":=" *)
let stack = ref [Int*] []
(* (assignment), "!" (dereferencing), ";" (sequencing) *)
let fun push(x : Int) : [] =
let fun push(x : Int) : [] =
stack := [x; !stack]
stack := [x; !stack]
...
@@ -13,10 +13,12 @@ let fun push(x : Int) : [] =
...
@@ -13,10 +13,12 @@ let fun push(x : Int) : [] =
let fun pop ([] : []) : Int =
let fun pop ([] : []) : Int =
match !stack with [x; y] -> stack := y; x | _ -> raise "Empty stack"
match !stack with [x; y] -> stack := y; x | _ -> raise "Empty stack"
(* In a pattern [ ... ; y] the variable y captures the rest of the *)
(* In a pattern [ ... ; y] the variable y captures the tail of the *)
(* sequence. It is equivalent to [ ... y::_*]. *)
(* sequence. It is equivalent to [ ... y::_*]. *)
(* In an expression [ ... ; e ] the expression e denote the tail of*)
(* In an expression [ ... ; e ] the expression e denotes the tail *)
(* the sequence. It is equivaent to [ ... ] @ y *)
(* of the sequence. It is equivalent to [ ... ] @ e *)
;;
;;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment