value restrictionの説明
MLの値多相は
# let f = ref (fun x -> x) ;; val f : ('_a -> '_a) ref = {contents =} # f := not ;; - : unit = () # !f "abc" ;; Characters 3-8: !f "abc" ;; ^^^^^ This expression has type string but is here used with type bool
とか高階関数で説明されることがよくありますが、
# let x = ref ;;
val x : '_a list ref = {contents = }
# x := [true] ;;
- : unit = ()
# List.hd !x + 123 ;;
Characters 0-10:
List.hd !x + 123 ;;
^^^^^^^^^^
This expression has type bool but is here used with type int
とかリストで説明したほうがわかりやすいかと。