Unused "type" among arguments of a function?

Recently, I was surprised to realize that the following is accepted by OCaml :

─( 16:19:10 )─< command 0 >──────────────────────────────────────{ counter: 0 }─
utop # let example (type a) x="see?";;
val example : 'a -> string = <fun>
─( 16:19:11 )─< command 1 >──────────────────────────────────────{ counter: 0 }─
utop # example 5;;
- : string = "see?"
─( 16:19:35 )─< command 2 >──────────────────────────────────────{ counter: 0 }─
utop # example "6";;
- : string = "see?"

I expected the first command to be a syntax error, and thought the type keyword’s only use is to define new type. Seems that I was wrong … Where is this documented and explained in the manual ?

That’s a “locally abstract type”, documented here in the manual. (I agree that it’s not easy to look for when you don’t know how it’s called!)

Thanks for that kind remark which makes me feel a little less stupid …

1 Like