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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:01:42+00:00 2026-05-26T01:01:42+00:00

In C++, recursive templates and constant values as template parameters allows to do interesting

  • 0

In C++, recursive templates and constant values as template parameters allows to do interesting examples of code generation and compile-time execution, such as the factorial.

Is it possible to do similar things in OCaml, using parametric polymorphism, functors, or other concepts?

  • 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-26T01:01:43+00:00Added an answer on May 26, 2026 at 1:01 am

    The ocaml inteference system uses unification. You can consider it a computational device, and in this case it has a feeling of logic programming. But the possibilities are rather restricted as this was never one of the goals of the type system. As you will see in the page suggested by Jeffrey, type-level computations through unification are actually rather limited (hard to express eg. multiplication). Haskell has a more powerful constraint language, abut again I’m not sure logic programming in the type system is a good way to go.

    The other part of the OCaml type system can do type-level computation is in its module and functor language. Functors allow to express type-level computations in a flavor that has been linked to the formal programming language Fω. You could probably encode church numerals at the type level in the module language, but I don’t see what you could do with this, as it is seems quite difficult to retrieve the results in an useful, exploitable form. In particular, I don’t see how to turn that type information back into values usable by your program, as C++ or D do with their compile-time constant computation.

    So yes, the type system of OCaml (and most functional language, that would hold of SML, Haskell and Scala as well) has some computational strength, but no, I wouldn’t expect to do particularly useful pre-computation with them; and it’s certainly not standard practice among OCaml programmers. Types are best seen as types, that bring static guarantees about the values they classify.

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

Sidebar

Related Questions

Here is my first code in variadic templates : void print_f() { } template<typename
This code involves a recursive Stored Procedure call and a not so great method
I have a matrix class with the size determined by template parameters. template <unsigned
at the moment I'm really interested in expression templates and want to code a
I have a recursive template so that I can update a count. In the
Can some one explain the below, rather complex recursive generic template usage? public abstract
This question is just out of curiosity. In recursive templates if we forget to
Consider the following JavaScript code which has a recursive boom function function foo() {
In my previous question I asked is recursive explicit template instantiation possible . I
I have a recursive template definition (I just made up that term). I think

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.