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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:34:59+00:00 2026-05-16T04:34:59+00:00

I’m developing some algorithms in OCaml which need some parts to be pluggable so

  • 0

I’m developing some algorithms in OCaml which need some parts to be “pluggable” so that part of the computation is left to specific computators.

Just to make an example suppose I have a signature like this one:

module type Algorithm = sig
    val feed : float -> unit
    val nth : int -> (float -> float)
end

And two different implementations that will be Alg1 and Alg2. This Algorithm module should represent the interface for various implementations like these two one.

Now I need another component, let’s call it Executor that will be the module that uses Alg1 or Alg2 throught their interface..

Reading about functors it seems that I should need a functor that takes an Algorithm and produces a ConcreteExecutor with a specific implementation of the algorithm I need. So that Executor is a sort of module that is parametrized over one of its components..

Am I right? Is it the best way to obtain what I need? I’m wondering thinkgs like these because I come from a Java/C++ background so I’m used to use interfaces and abstract classes and I need to get into this functor/module abstraction issue in the correct way.

Which is the correct syntax to obtain what I want?

Thanks in advance

  • 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-16T04:34:59+00:00Added an answer on May 16, 2026 at 4:34 am

    Yup, it sounds like functors are what you want. In fact, you can take a look at how the standard library uses functors as the source code is available. On my machine it’s located at /usr/lib/ocaml/3.10.2/. As an example, set.mli contains the following:

    module type OrderedType =
      sig
        type t
        val compare : t -> t -> int
      end
    
    module type S
      sig
        ...
      end
    
    module Make (Ord : OrderedType) : S with type elt = Ord.t
    

    When you want to use a set in OCaml you do:

    module SSet = Set.Make(String);;
    

    So with your code, Algorithm replaces OrderedType, Alg1/Alg2 replaces String, Executor replaces Make, and ConcreteExecutor is the result of Executor(Alg1/Alg2). You’ll also notice that string.mli/ml doesn’t contain any mention of OrderedType. String is an OrderedType by virtue of it having a type t that is used by a function compare. You don’t need to explicitly say that String is an OrderedType.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.