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 370151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:59:24+00:00 2026-05-12T13:59:24+00:00

I want to use OCaml to generates sets of data and make comparisons between

  • 0

I want to use OCaml to generates sets of data and make comparisons between them. I have seen the documentation for Module types like Set.OrderType, Set.Make, etc, but I can’t figure out how to initialize a set or otherwise use them.

  • 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-12T13:59:25+00:00Added an answer on May 12, 2026 at 1:59 pm

    Sets are defined using a functorial interface. For any given type, you have to create a Set module for that type using the Set.Make functor. An unfortunate oversight of the standard libraries is that they don’t define Set instances for the built-in types. In most simple cases, it’s sufficient to use Pervasives.compare. Here’s a definition that works for int:

    module IntSet = Set.Make( 
      struct
        let compare = Pervasives.compare
        type t = int
      end )
    

    The module IntSet will implement the Set.S interface. Now you can operate on sets using the IntSet module:

    let s = IntSet.empty ;;
    let t = IntSet.add 1 s ;;
    let u = IntSet.add 2 s ;;
    let tu = IntSet.union t u ;;
    

    Note that you don’t have to explicitly define the input structure for Set.Make as an OrderedType; type inference will do the work for you. Alternatively, you could use the following definition:

    module IntOrder : Set.OrderedType = struct
      type t = int
      let compare = Pervasives.compare
    end
    
    module IntSet = Set.Make( IntOrder )
    

    This has the advantage that you can re-use the same module to instantiate a Map:

    module IntMap = Map.Make( IntOrder )
    

    You lose some genericity in using functors, because the type of the elements is fixed. For example, you won’t be able to define a function that takes a Set of some arbitrary type and performs some operation on it. (Luckily, the Set module itself declares many useful operations on Sets.)

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

Sidebar

Related Questions

i want use some data from a website with web service. i have a
I want to use regexps in OCaml and it seems that Str module provides
I have some properties defined by the user, and then I want use them
I have a transaction log file in CSV format that I want use to
I have a easy select tag: <select> <option></option> <option></option> </select> Then I want use
I want nice operators for complex arithmetic to make my code more readable. Ocaml
I have a list called list_ds of a custom-defined data structure in my OCaml
If I'm programming in the OCaml toploop and I want to use a package
I want use ORDER BY RAND() query mysql. But I have some question want
I need to use HTML comments to store specific data, but I don't want

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.