$ cat stack.ml
class ['a] stack init = object
val mutable v = init
method pop =
match v with
| hd :: tl ->
v <- tl;
Some hd
| [] -> None
method push hd =
v <- hd :: v
end ;;
$ ./app.native stack.ml
((pid 85452) (thread_id 0)
((human_readable 2015-05-18T15:57:48-0400)
(int63_ns_since_epoch 1431979068026404000))
"unhandled exception in Async scheduler"
("unhandled exception"
((lib/monitor.ml.Error_
((exn "Assert_failure lib/conv.ml:487:15")
(backtrace
("Raised at file \"lib/conv.ml\", line 487, characters 15-27"
"Called from file \"lib/conv.ml\", line 215, characters 26-43"
"Called from file \"lib/conv.ml\", line 229, characters 17-44"
"Called from file \"lib/conv.ml\", line 234, characters 8-27"
"Called from file \"lib/exn.ml\", line 38, characters 50-65"
"Called from file \"list.ml\", line 73, characters 12-15"
"Called from file \"list.ml\", line 73, characters 12-15"
"Called from file \"lib/core_list.ml\", line 328, characters 16-30"
"Called from file \"lib/result.ml\", line 56, characters 16-19"
"Called from file \"lib/deferred.ml\", line 15, characters 64-67"
"Called from file \"lib/job_queue.ml\", line 164, characters 6-47" ""))
(monitor
(((name main) (here ()) (id 1) (has_seen_error true)
(is_detached false) (kill_index 0))))))
(Pid 85452))))
The outcome of this script ends up being an Uneval of an Internal_error, and the printing of such a value is the source of the above error. If we comment out the exception printer here, then the problem goes away:
$ ./app.native stack.ml
(* part 0 *)
# class ['a] stack init = object
val mutable v = init
method pop =
match v with
| hd :: tl ->
v <- tl;
Some hd
| [] -> None
method push hd =
v <- hd :: v
end ;;
oloop-top: sending the phrase eval outcome failed because: output_value: functional value
A second bug is that the specific error seems wrong. The expected outcome is:
Error: Some type variables are unbound in this type:
class ['a] stack :
'b list ->
object
val mutable v : 'b list
method pop : 'b option
method push : 'b -> unit
end
The method pop has type 'b option where 'b is unbound