Trying to create a functor which would, given 2 modules of signature Set.OrderedType
, create a module of signature Set.OrderedType
representing objects of type the product of the two types, (Not really clear sorry) and being therefore able to compare said objects (using for instance the lexicographic order), to be able to use this module for Set
But, when I try to do this
module CartesianProduct2 (M1 : Set.OrderedType) (M2 : Set.OrderedType) : Set.OrderedType = struct type t = M1.t * M2.t let compare (a : t) (b : t) : int = match (a, b) with | (c, d), (e, f) -> if M1.compare c e <> 0 then M1.compare c e else M2.compare d fend(*A module to handle char*char *)module Char2 = CartesianProduct2 (Char) (Char)
The code works fine except from the fact that OCaml does not recognize Char2.t
as char*char
:( meaning that when I try to compare two char*char instances like this:
Char2.compare ('a', 'b') ('c', 'd')
OCaml raises an error, saying: This expression has type 'a * 'b but an expression was expected of type Char2.t