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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:11:32+00:00 2026-05-18T04:11:32+00:00

I started learning functional programming (OCaml), but I don’t understand one important topic about

  • 0

I started learning functional programming (OCaml), but I don’t understand one important topic about fp: signatures (I’m not sure if it’s a proper name). When I type something and compile with ocaml, I get for example:

# let inc x = x + 1 ;;
val inc : int -> int = <fun>

This is trivial, but I don’t know, why this:

let something f g a b = f a (g a b)

gives an output:

val something : (’a -> ’b -> ’c) -> (’a -> ’d -> ’b) -> ’a -> ’d -> ’c = <fun>

I suppose, that this topic is absolutely basics of fp for many of you, but I ask for help here, because I haven’t found anything on the Internet about signatures in OCaml (there are some articles about signatures in Haskell, but not explanations).

If this topic somehow will survive, I post here several functions, which signatures made me confused:

# let nie f a b = f b a ;; (* flip *)
val nie : (’a -> ’b -> ’c) -> ’b -> ’a -> ’c = <fun>

# let i f g a b = f (g a b) b ;;
val i : (’a -> ’b -> ’c) -> (’d -> ’b -> ’a) -> ’d -> ’b -> ’c = <fun>


# let s x y z = x z (y z) ;;
val s : (’a -> ’b -> ’c) -> (’a -> ’b) -> ’a -> ’c = <fun>

# let callCC f k = f (fun c d -> k c) k ;;
val callCC : ((’a -> ’b -> ’c) -> (’a -> ’c) -> ’d) -> (’a -> ’c) -> ’d = <fun>

Thank you for help and explanation.

  • 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-18T04:11:33+00:00Added an answer on May 18, 2026 at 4:11 am

    There are a couple of concepts you need to understand to make sense of this type signature and I don’t know which ones you already do, so I tried my best to explain every important concept:

    Currying

    As you know, if you have the type foo -> bar, this describes a function taking an argument of type foo and returning a result of type bar. Since -> is right associative, the type foo -> bar -> baz is the same as foo -> (bar -> baz) and thus describes a function taking an argument of type foo and returning a value of type bar -> baz, which means the return value is a function taking a value of type bar and returning a value of type baz.

    Such a function can be called like my_function my_foo my_bar, which because function application is left-associative, is the same as (my_function my_foo) my_bar, i.e. it applies my_function to the argument my_foo and then applies the function that is returned as a result to the argument my_bar.

    Because it can be called like this, a function of type foo -> bar -> baz is often called “a function taking two arguments” and I will do so in the rest of this answer.

    Type variables

    If you define a function like let f x = x, it will have the type 'a -> 'a. But 'a isn’t actually a type defined anywhere in the OCaml standard library, so what is it?

    Any type that starts with a ' is a so-called type variable. A type variable can stand for any possible type. So in the example above f can be called with an int or a string or a list or anything at all – it doesn’t matter.

    Furthermore if the same type variable appears in a type signature more than once, it will stand for the same type. So in the example above that means, that the return type of f is the same as the argument type. So if f is called with an int, it returns an int. If it is called with a string, it returns a string and so on.

    So a function of type 'a -> 'b -> 'a could take two arguments of any types (which might not be the same type for the first and second argument) and returns a value of the same type as the first argument, while a function of type 'a -> 'a -> 'a would take two arguments of the same type.

    One note about type inference: Unless you explicitly give a function a type signature, OCaml will always infer the most general type possible for you. So unless a function uses any operations that only work with a given type (like + for example), the inferred type will contain type variables.

    Now to explain the type…

    val something : ('a -> 'b -> 'c) -> ('a -> 'd -> 'b) -> 'a -> 'd -> 'c = <fun>
    

    This type signature tells you that something is a function taking four arguments.

    The type of the first argument is 'a -> 'b -> 'c. I.e. a function taking two arguments of arbitrary and possibly different types and returning a value of an arbitrary type.

    The type of the second argument is 'a -> 'd -> 'b. This is again a function with two arguments. The important thing to note here is that the first argument of the function must have the same type as the first argument of the first function and the return value of the function must have the same type as the second argument of the first function.

    The type of the third argument is 'a, which is also the type of the first arguments of both functions.

    Lastly, the type of the fourth argument is 'd, which is the type of the second argument of the second function.

    The return value will be of type 'c, i.e. the return type of the first function.

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

Sidebar

Related Questions

I've just started learning Functional Programming (Scheme). But I still have problems thinking functionally.
I just recently have started learning about the wonders of **kwargs but I've hit
I'm just started learning scheme and can't quite understand why this function does not
I am new to functional programming in general and started learning F# recently. I
I started learning oop php and I don't understand how to make a method
I have just started learning about socket programming and learned about winsock and achieved
Started learning algorithms. I understand how to find theta-notation from a 'regular recurrence' like
Started learning Wicket after ASP.NET MVC and feel a little bit confused about managing
I started learning JavaScript a while ago. It's a fairly easy programming language considering
I'm a real noob who just started learning 3d programming and i have a

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.