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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:43:44+00:00 2026-05-24T05:43:44+00:00

I would like to know, in Ocaml, whether a partial typing info. can be

  • 0

I would like to know, in Ocaml, whether a partial typing info. can be drawn by some existed functionality of toplevel/compiler, for a program that does not compile? Let me explain.

In Ocaml, it’s well known that inferred typed can be retrieved by -annot file. However, sometimes we have a piece of code that does not compile due to some typing error. It gives a error exported to the toplevel, of this pattern

"This expression has type A, but was expected type B" 

An artificial example would be

# let x =  
  let y = 5  in
  not y;;
    Characters 32-33:
    not y;;
        ^
Error: This expression has type int 
       but an expression was expected of type bool

The programmer of this piece of code should understand well the 2nd part of this message, i.e.,
“y is expected of type bool”, because of the “not y” part. However, she/he might have some difficulty to understand the 1st part of this error message: how this “y” is inferred to have type “int”? Thus it would be interesting to have a partial set of inferred types, before the type conflicts are raised. For the example above, one would like the interpreter tells that the first “y” (from “let y = 5”) is of type int, by which I will know the reason why the second “y” (from “not y”) is infered to be of type int.

Could you tell me whether the described functionality is already provided by some ocaml interpreter/compiler?

In general words, my question is: can ocaml toplevel, or its interpreter, yield partially inferred types that user can retrieve in order to more efficiently find the source of their typing error?

This question might not make sense because of the non-uniqueness of the partially inferred type annotation. However, the example example should show that at least for some cases, and some partially inferred types have its usage.

Thank you for your ideas.

  • 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-24T05:43:45+00:00Added an answer on May 24, 2026 at 5:43 am

    The type annotations by generated by the -annot switch are available even if the program did not compile. You’ll see types for the expressions that the compiler got through, and some of them may be incomplete. This doesn’t tell you the compiler’s reasoning for inferring the types, but it does tell you how far the compiler went and lets you explore what it’s inferred.

    For example, with this source code:

    let x = [(let y = 5 in not y); true];;
    
    • x has the type _a list (the compiler hasn’t gotten far enough to figure out _a).
    • y has the type int.
    • not has the type bool -> bool.
    • The error message is that the second occurrence of y has the type int (and we’ve seen where it was inferred) but the context expects the type bool (and we can see that, since not is a function whose argument type is bool).

    I don’t know how to see these types from the toplevel, but if you have a source file with your code, you can run ocamlc -c -annot, open the source in a suitable editor (such as Emacs) and view the inferred types whether the compilation succeeded or not.

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

Sidebar

Related Questions

i would like know some reference. I know i can googling it. but prefer
I would like know whether we can highlight text (colors) of already created PDF
I would like to know, whether the url below by google can change in
I would like to know if I can open 2 different diagrams using MS
I would like know the limit of maximum number of rows that can be
would like to know how can this be implemented in Joomla. I have a
I would like to know whether we have a chance to see what are
i would like know how can i add a style when a item of
Would like to know what a programmer should know to become a good at
Would like to know the c# code to actually retrieve the IP type: Static

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.