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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:24:25+00:00 2026-06-18T02:24:25+00:00

In ocaml, let’s say we have: type t = A of int | B

  • 0

In ocaml, let’s say we have:

type t = A of int | B of string
let x = [A 5; B "y"]

Then, we can iterate the list, and use match statement to decide what to do with A or B.

In java, we could have:

ArrayList<Object> x = new ArrayList<Object>();
x.add(new Integer(5));
x.add("y");

On the array list iteration, we would have to instanceof and downcast to work with data.

Is it true that, internally, ocaml carries runtime type information as java, and the type matching statement works like java instanceof-downcast, but type is safe because there’s no way one can write

if (element instanceof Integer) {
  String e = (String) element;
}
  • 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-06-18T02:24:26+00:00Added an answer on June 18, 2026 at 2:24 am

    No and Yes. In general OCaml does not carry any runtime type information for every value around (As was already said in Jeffrey’s answer). And that is safe because of the design of the type system as a completely static type system. A and B are not types in OCaml, they are constructors. And constructors are distinguishable at runtime. But only between constructors of one type. So, the OCaml compiler represents only the bare minimum at runtime, that is necessary to implement pattern matching.

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

Sidebar

Related Questions

In Ocaml, tuples with different arities have different type and value constructors: # let
Let's say I have three value constructors: A { a :: Int } B
Have a look at this F#/OCaml code: type AllPossible = | A of int
How do I convert the string option data type to string in Ocaml? let
As a beginner in Ocaml, I have this current working code: ... let ch_in
I have function 'my_a' in OCaml, which could have a very complicated return type:
It is typical in OCaml or F# to have successive let bindings in the
I have an ocaml type : type t = A | B | ...
I've been thinking about how type inference works in the following OCaml program: let
I need an OCaml map with keys of type int so I am using

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.