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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:14:30+00:00 2026-05-26T03:14:30+00:00

I am evaluating a very simple piece of code in Ocaml toplevel: let p5

  • 0

I am evaluating a very simple piece of code in Ocaml toplevel:

let p5 () = print_int 5;;
p5 ();;

print_string "*************************";;

let p4 = print_int 4;;
p4;; 

And it returns:

val p5 : unit -> unit = <fun>
#   5- : unit = ()
#   *************************- : unit = ()
#   4val p4 : unit = ()
#   - : unit = ()

My questions are

  1. What does () mean in let p5 () = print_int 5;;?
  2. What do - and () mean in # 5- : unit = ()?
  3. Is p4 a function?
  4. Why is there a 4 in the beginning of # 4val p4 : unit = ()?
  5. It seems that () could be used in Ocaml code to hide side effect, could anyone show me an example?
  • 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-26T03:14:30+00:00Added an answer on May 26, 2026 at 3:14 am

    Here some answers:

    1. () is the unit type value. The unit type is a type with only one value. This is usually used to produce functions which either return nothing meaningful or take nothing meaningful. Remember, that in OCaml all functions alway have to return something and take some arguments, so the unit type is used to get around this limitation. Think of this similar to the void type in C, C++ or Java.
    2. There are two lines interleaved. The 5 is printed by the print_int function and not by the toplevel. The toplevel just returns - : unit = () without the 5. The toplevel is telling you that it did not create any new bindings - and that the last returned value is of type unit and has the value ().
    3. No. It does not take any arguments, so it is not a function.
    4. Again there are two lines interleaved. The 4 is printed by the print_int function. At this time, the toplevel is telling you, that it created a new binding p4, that this variable carries a value of type unit and that the stored value is ().
    5. No, () is not used to hide side effects. It is usually used to create functions, which have side effects, and thus need not take any kind of argument.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background info: I've set up a very simple .NET solution in VS2008 that contains
I have created a very simple bookmarklet to submit the url of the site
Simple question that probably has a very simple answer. I am writing date strings
I'm evaluating subversion's branch/merge capabilities, and I decided to do a simple test -
I'm evaluating the possibility of developing an Eclipse plugin to modify the source code
I am very lost in Xcode 4. Watching a simple variable is a nightmare.
So say I have the following very simple macro, along with a bit of
While evaluating the advantages and disadvantages of moving our Subversion-based repository over to Git,
When evaluating dojo.require statements, dojo tracks which modules and resources have been required and
When evaluating the success of products such as the iPhone, iPad, Google, Twitter, YouTube,

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.