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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:26:51+00:00 2026-06-07T21:26:51+00:00

let () = Random.self_init();; let _ = Random.self_init ();; │- : unit = ()

  • 0
let () = Random.self_init();;
let _ = Random.self_init ();;
│- : unit = ()

It seems “let ()” returns nothing ?

Sincerely!

  • 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-07T21:26:54+00:00Added an answer on June 7, 2026 at 9:26 pm

    let is the keyword used to define new variables, like in the following construct:

    let pattern = expr
    

    For instance

    let a = 2
    

    assigns the value 2 to the name a. (Note this is not a way to assign a value to an already existing variable, but this is another topic).

    But the pattern to the left of the = sign can be more than just a name. For instance

    let (a,b) = (42,"foo")
    

    defines both a and b, to be respectively 42 and "foo".
    Of course, the types on both sides must match.
    Which is the case here: both sides are of type int * string.

    The expressions to the right of the = sign can also be elaborated, for instance

    let foo =
      let temp = String.make 10 'a' in
      temp.[2] <- 'b';
      temp
    

    defines foo as the string "aabaaaaaaa". (As a side note, it also ensures that temp is local to this code snippet).

    Now, let’s use both: on the left, a pattern matching values of type unit, and on the right, an expression of type unit:

    let () = Printf.printf "Hello world!\n"
    

    Which explains the let () = construct.
    Now, about the let _, one simply needs to know that _ can be used in a pattern as a wildcard: it matches values of any type and does not bind any name. For instance

    let (a,_) = (42,"foo")
    

    defines a as 42, and discards the value "foo". _ means “I know there is something here and I explicitly say I will not use it, so I don’t name it”. Here _ was used to match values of type string, but it can match value of any type, like int * string:

    let _ = (42,"foo")
    

    which does not define any variable and is not very useful. Such constructs are useful when the right hand side has side effects, like this:

    let _ = Printf.printf "Hello world!\n"
    

    which explains the second part of the question.

    Practical purposes

    Both are used and it’s rather a matter of taste whether to use one or the other.

    let () = is slightly safer as it has the compiler check that the right hand side is of type unit.
    A value of any other type than unit is often a bug.

    let _ = is slightly shorter (I’ve seen this argument). (Note that with an editor that automatically closes parenthesizes, the number of keystrokes is the same 😉

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

Sidebar

Related Questions

Let's say you have a random number generator spitting out numbers between 1 and
Let's use the following code (conftest.py) : import random def test_val(): value = random.random()
I have some random string, let's say : s = This string has some
I'm using Java to parse HTML from a random website, let's say it's http://google.com
now let's think we got a random zip file so how do I know
So let's say you want to generate a random number, but you want it
Let's say that if I read from www.example.com/number, I get a random number. In
Let say that I would like to get an random double value wich is:
Let's say I have a table with the following contents: (just some random values)
My program requires multiple random recursions, and I have to manually let the script

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.