Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 597

Implementing functions in module types

$
0
0

I have the following module type:

module type Element = sig  type t  type mystruct = {x: int; y: int}  val (<) : t -> t -> bool  val string_of_element : t -> string  (* val (>) : t -> t -> bool = not (<) *)end

Where as you can see, I want the type t to be generic but I want mystruct to have a specific structure. The problem is that when I create a module MyInteger that "implements" module Element as follow:

module MyInteger = struct  type t = int  let (<) a b = a < b  let string_of_element = string_of_intend

It complains that

The type `mystruct' is required but not provided

And it does not work unless I redefine type mystruct in this module.

I don't understand why it just don't use the type I defined in the module type? Is there a way I can make it do that?

Same thing with function (>), how can I make OCaml consider (>) the opposite of (<) whatever it is?


Viewing all articles
Browse latest Browse all 597

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>