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

  • SEARCH
  • Home
  • 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 145969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:31:05+00:00 2026-05-11T08:31:05+00:00

I am having a bit of a problem with a functor (and it’s resultant

  • 0

I am having a bit of a problem with a functor (and it’s resultant type). Below, I have a Set functor that uses an Ordered type. I actually used the set.ml that comes with OCaml for some guidance, but I seem to be doing everything ahem right. I created an Ordered module with integers and applied it to the Set functor to get the last module on this code sample, IntSet.

The next line fails, when I try to insert an integer. I get the following type error:

Error: This expression has type int but is here used with type          SetInt.elt = Set(OrdInt).elt 

Don’t get me wrong, the type system is correct here. The top level reports that the type of the SetInt.elt is Set(OrdInt).elt, but when I do the same operations to set up a Set using the one provided by OCaml the ‘same’ line is, SetInt.elt = OrderedInt.t. Seems like I should be getting SetInt.elt = Ordered.t.

This is so simple, I’m probably just missing some stupid detail! argh!

Please Note: I have simplified the member/insert functions here since this issue has to do with types.

module type Ordered =   sig     type t      val lt : t -> t -> bool     val eq : t -> t -> bool     val leq : t -> t -> bool   end  module type S =   sig     type elt     type t     exception Already_Exists     val empty  : t     val insert : elt -> t -> t     val member : elt -> t -> bool   end  module Set (Elt:Ordered) : S =    struct     type elt = Elt.t     type t = Leaf | Node of t * elt * t     exception Already_Exists     let empty = Leaf     let insert e t = t     let member e t = false   end  module OrdInt : Ordered =   struct     type t = int     let lt a b = a < b     let eq a b = a = b     let leq a b = a <= b   end  module IntSet = Set (OrdInt)  (* line that fails *) let one_elm = IntSet.insert 1 IntSet.empty 
  • 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. 2026-05-11T08:31:05+00:00Added an answer on May 11, 2026 at 8:31 am

    You need to change these two lines

    module Set (Elt:Ordered) : S =  module OrdInt : Ordered = 

    to

    module Set (Elt:Ordered) : S with type elt = Elt.t =  module OrdInt : Ordered with type t = int = 

    Without these, the modules will not have signatures that expose the types elt and t as int.

    [Edit]: The set.ml doesn’t have the ‘with’ bit, because there’s a sml.mli, which declares the signature for the functor and it does have the ‘with’. Also, OrdInt doesn’t need ‘with’ if you don’t explicitly specify a signature for it, like this:

    module OrdInt = 

    You can also construct the set by defining the module in place:

    module IntSet = Set (struct  type t = int  let lt a b = a < b  let eq a b = a = b  let leq a b = a <= b end)  
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a bit of a problem, Due to the source-control set-up we use, each
I'm having a bit of a problem. I have a datatable in the parent
I'm having a bit of a problem here. We have 2 urls let me
Having a bit of a problem with the AJAX Accordion Control... I have two
I'm having a little bit of problem with my derived class. Basically I have
I'm having a bit of a problem with a Prolog exercise. Assume i have
I'm having a bit of a problem normalizing a UPC string code so that
I'm having a bit of problem with casting and datagrids. I have a LINQ
I am having a bit of problem regarding Swing. I have a JFrame called
I'm having a bit of a problem I have created a post and it

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.