Where is the option type defined?

#1

I’m almost positive that it was in Pervasives–but it’s not there now. In which module is the type 'a option actually defined?

0 Likes

#2

It’s in initial typing environment, along with other builtin types like int, bool, etc.
This file contains all the types that the typechecker needs to know.

The reason the typechecker needs to know about option specifically (and not, for example, ref) is because of the syntax let f ?foo = <body>. In <body>, foo has type _ option. Additionally, ?(foo=2) desugars to pattern matching, so the typechecker must know about option, Some and None.

5 Likes