OCaml functors :: counter-intuitive behaviour

前端 未结 4 460
[愿得一人]
[愿得一人] 2021-01-11 11:18

I am experimenting with the module language of OCaml (3.12.1), defining functors and signatures for modules and so on, mostly following the examples from Chapter 2 of the OC

4条回答
  •  渐次进展
    2021-01-11 12:14

    When you write:

    module IntType : SOMETYPE = struct type t = int end ;;
    

    You are constraining the signature of InType to be exactly SOMETYPE. This means, for instance, that the type t is now becoming an abstract type (whose implementation is unknown to the typer).

    So IdentityInt.f type is still IntType.t -> IntType.t, but, by using a signature constraint, you've explicitly removed the equation IntType.t = int from the typer knowledge. The error message you get tells you exactly that.

提交回复
热议问题