Source

ocaml-dynatvar / dyntest.ml

Full commit
open Dynvar
;

value tyint = mktype "int"
;

value tystring = mktype "string"
;

value v1 = var tyint 123
  and v2 = var tystring "kva"
;

value vlist = [v1; v2]
;

value () =
  Printf.printf "v1 = %i, v2 = %s\n"
    (get tyint v1) (get tystring v2)
;

value tycatch f x =
  try f x
  with
  [ Type_error (type_value, type_usedwith) ->
      Printf.eprintf "value has type %S but used with type %S\n"
      type_value type_usedwith
  ]
;

value () =
tycatch
  (fun () ->
     Printf.printf "int as string = %s\n" (get tystring v1)
  )
  ()
;

value () =
tycatch
  (fun () ->
     Printf.printf "string as int = %i\n" (get tyint v2)
  )
  ()
;