type 'a stack = 'a list ref
let create () = ref []
let add stack x = stack := x::!stack
let pop stack =
match !stack with
[] -> raise (Invalid_argument "pop")
|x::xs -> stack := xs;
x
let size_of stack =
List.length !stack
let my_stack = create ()
let _ = add my_stack 3;
let popped = pop my_stack in Printf.printf "%d\n" popped
When I try to compile this
ocamlc Stack.ml -o Stack
File "Stack.ml", line 20, characters 26-28:
20 | let popped = pop my_stack in Printf.printf "%d\n" popped;
^^
Error: Syntax error
This same code works in TryOcaml online editor.
Thanks in advance!