diff options
author | Son Ho | 2021-11-03 12:04:57 +0100 |
---|---|---|
committer | Son Ho | 2021-11-03 12:04:57 +0100 |
commit | b582131d54a41a707c4ab75c3bc03251601fb230 (patch) | |
tree | dc72d71a86b4dbfecb4be77e47c489477154ba78 /src/Identifiers.ml | |
parent | 47a8983a5e95e306bddbcf031777ad781479fdd8 (diff) |
Split main.ml between Identifiers.ml and Types.ml
Diffstat (limited to '')
-rw-r--r-- | src/Identifiers.ml | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Identifiers.ml b/src/Identifiers.ml new file mode 100644 index 00000000..b46b00ee --- /dev/null +++ b/src/Identifiers.ml @@ -0,0 +1,42 @@ +exception IntegerOverflow of unit + +(** Signature for a module describing an identifier. + + We often need identifiers (for definitions, variables, etc.) and in + order to make sure we don't mix them, we use a generative functor + (see [IdGen]). +*) +module type Id = sig + type id + + type 'a vector + + val zero : id + + val incr : id -> id + + val to_string : id -> string +end + +(** Generative functor for identifiers. + + See [Id]. +*) +module IdGen () : Id = struct + type id = int + + type 'a vector = 'a list (* TODO: use a map *) + + let zero = 0 + + let incr x = + (* Identifiers should never overflow (because max_int is a really big + * value - but we really want to make sure we detect overflows if + * they happen *) + if x == max_int then raise (IntegerOverflow ()) else x + 1 + + let to_string = string_of_int +end + +type name = string list +(** A name such as: `std::collections::vector` *) |