Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4097668
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:12:11+00:00 2026-05-20T20:12:11+00:00

I have defined two module types and two modules module type FOO = sig

  • 0

I have defined two module types and two modules

module type FOO = sig type e end
module type BAR = sig type t end    
module Foo : FOO = struct type e = int end
module Bar : BAR = struct type t = int end

Then I define a functor as

module Fun (F:FOO) (B:BAR with type t = F.e) = struct type x = string end

(this is a toy example, please ignore the fact that F and B are not used by the functor)

Now, if I define the module

module Bla = Fun (Foo) (Bar)

I get

Error: Signature mismatch:
       Modules do not match:
         sig type t = Bar.t end
       is not included in
         sig type t = Foo.e end
       Type declarations do not match:
         type t = Bar.t
       is not included in
         type t = Foo.e

Although both Bar.t and Foo.e are defined as int OCaml considers Bar.t and Foo.e to be different. That’s just the way the typing system works and it makes sense to consider these two types different in general (c.f. last paragraph of Functors and Type Abstraction).

Question: Sometimes I may want this to pass type checking because for my purposes they can be considered equal. Is there a way to relax this?


Using gasche’s suggestion of removing coercion, the above code can be written as

module type FOO = sig type e end
module type BAR = sig type t end
module Foo = struct type e = int end
module Bar = struct type t = int end
module Fun (F : FOO with type e=int) (B : BAR with type t = int) = struct type x = F.e * B.t end
module Bla = Fun (Foo) (Bar)

which compiles fine. Strangely, I get

# let f x : Bla.x = (x,x);;
val f : Foo.e -> Bla.x = <fun>

Question: why does it infer that x is Foo.e? It could as well be Bar.t?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:12:11+00:00Added an answer on May 20, 2026 at 8:12 pm

    The problem is how you define Foo and Bar : module Foo : FOO = .... By imposing this signature here, you “seal” the module and make the type abstract. It cannot be reverted. You should remove the : FOO coercion here, and use it later when you need the abstraction. You could also use module Foo : (FOO with type e = int) = ....

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex data structure (user-defined type) on which a large number of
Hey all, I'm learning Doctrine + Symfony and I may have chosen too complex
Here are my attempts so far: module Main where data FooT = One |
Using the json module in python 2.6, I'm experiencing some unexpected behavior when passing
This will hopefully be an easy one. I have an F# project (latest F#
When I'm writing a function in a utility module to be used again, I
How do you get the logical xor of two variables in Python? For example,
As an exercise, and mostly for my own amusement, I'm implementing a backtracking packrat
XML Serialization from MSDN : Serializes and deserializes objects into and from XML documents.
Looking at examples about socket programming, we can see that some people use AF_INET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.