Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax for module option

Tags:

ocaml

I'm trying to make a type with an optional map:

module CharMap = Map.Make(Char)
type trie = bool * CharMap.t option

But this results in a syntax error:

Error: The type constructor CharMap.t expects 1 argument(s),
       but is here applied to 0 argument(s)

What am I doing wrong?

like image 461
Nick Heiner Avatar asked Sep 22 '26 11:09

Nick Heiner


1 Answers

CharMap.t is a map from char to 'a, so actually its type is 'a Charmap.t, so you forget to specify the polymorphic argument. So you should write:

type 'a trie = bool * 'a CharMap.t option

If you want your map to be monomorphic (for instance char -> int) you can just write:

type trie = bool * int CharMap.t option
like image 95
Thomas Avatar answered Sep 24 '26 04:09

Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!