Why does this work fine?
module Account = struct
type account_type = Current of float | Savings of float
end
let sarah = Account.Current 100.0;;
While the final line in the following produces an Error: syntax error
?
module Account = struct
type 'a account_type = [> `Current of float | `Savings of float ] as 'a
end
let pete = Account.`Current 100.0;;
That is, why can't I use the open union type outside the module without opening the module? I should say I've found out that changing the final line to:
open Account;;
let pete = `Current 100.0;;
works fine, but obviously this is cumbersome if I use account_type
a lot, or alternatively I have to open Account
at the start of any code section where account_type
is used, which means I'd sacrifice the abstraction I'd get by using a signature for Account
I've trawled through several OCaml tutorials as well as the INRIA documentation, and I can't find any mention of how you do this.
Is it possible to avoid having to open the module every time I want to use an account_type
?
Thanks in advance,
Zach