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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:10:34+00:00 2026-06-09T11:10:34+00:00

Trying to understand Ocaml’s mechanism for named parameters. I understand the basics, but the

  • 0

Trying to understand Ocaml’s mechanism for named parameters. I understand the basics, but the doc shows an example like this:

# let f ~x ~y = x - y;;
val f : x:int -> y:int -> int = <fun>

# let x = 3 and y = 2 in f ~x ~y;;
- : int = 1

What exactly is going on when only the tilde is used in application? Is it just shorthand for ~x:x, similar to definitions? If so, can someone explain why this:

# ListLabels.fold_left;;
- : f:('a -> 'b -> 'a) -> init:'a -> 'b list -> 'a = <fun>

# let add = (+) and i = 0 
in ListLabels.fold_left ~add ~i [1;2;3];;

produces

- : f:((add:(int -> int -> int) -> i:int -> 'a) ->
   int -> add:(int -> int -> int) -> i:int -> 'a) ->
init:(add:(int -> int -> int) -> i:int -> 'a) -> 'a = <fun>
  • 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-09T11:10:35+00:00Added an answer on June 9, 2026 at 11:10 am

    The man says
    “beware that functions like ListLabels.fold_left whose result type is a type variable will never be considered as totally applied.”

    Here is what happens in your example. Beware it’s a bit involved.

    # ListLabels.fold_left;;
    - : f:('a -> 'b -> 'a) -> init:'a -> 'b list -> 'a = <fun>
    

    is just the classic use: ListLabels.fold_left taks 3 arguments, namely a function labeled f, an initializer init and a list.

    Now, in

    let add = (+) and i = 0 
    in ListLabels.fold_left ~add ~i [1;2;3];;
    

    the application ListLabels.fold_left ~add ~i [1;2;3] is considered incomplete (as the man says). That means that `ListLabels.fold_left receives first its unamed argument, [1;2;3] and returns a function of type f:('a -> int -> 'a) -> init:'a -> 'a. Let us call this function foo.

    Since you’re giving two named arguments, labeled add and i, the type 'a is inferred to be a functional type, of type add:'c -> ~i:'d -> 'e.

    Based on the type of the variables add and i, the type 'c must be int -> int -> int, and 'd must be int.

    Replacing those values in the type 'a, we derive that the type 'a is add:(int -> int -> int) -> i:int -> 'e.
    And replacing this in the type of foo (I’m glad there is copy-pasting ;-), its type is

    f:((add:(int -> int -> int) -> i:int -> 'e)
        -> int
        -> (add:(int -> int -> int) -> i:int -> 'e))
    -> init:(add:(int -> int -> int) -> i:int -> 'e)
    -> (add:(int -> int -> int) -> i:int -> 'e)
    

    Removing unecessary parentheses, and alpha converting (i.e. renaming) 'e to 'a, we get

    f:((add:(int -> int -> int) -> i:int -> 'a)
        -> int
        -> add:(int -> int -> int) -> i:int -> 'a)
    -> init:(add:(int -> int -> int) -> i:int -> 'a)
    -> add:(int -> int -> int) -> i:int -> 'a
    

    That is the type of foo. But remember that you are passing two arguments to foo, labeled ~add and ~i. So the value you get at the end is not of type add:(int -> int -> int) -> i:int -> 'a but indeed of type 'a. And the whole type of your example is, as returned by the compiler,

    f:((add:(int -> int -> int) -> i:int -> 'a)
        -> int
        -> add:(int -> int -> int) -> i:int -> 'a)
    -> init:(add:(int -> int -> int) -> i:int -> 'a)
    -> 'a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to understand this MSDN sample but I'm confused about these lines: IAsyncResult result
I´m trying to understand and use the Picasa Api, I´m using this example https://developers.google.com/picasa-web/docs/2.0/developers_guide_java?hl=nl-NL
Trying to understand PNG format. Consider this PNG Image: The Image is taken from
Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults
Trying to understand Ruby a bit better, I ran into this code surfing the
Trying to understand the math of this code snippet. A token is provided which
Im trying to understand how class generics work and this bit just doesnt make
I am trying understand how multi queries work in mysqli. But I confess that
Trying to understand why this doesn't work. I keep getting the following errors: left
Trying to understand this binding process of the WPF. See the code at the

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.