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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:12:19+00:00 2026-06-08T09:12:19+00:00

I have stumbled upon lots of exercises that give you a function and ask

  • 0

I have stumbled upon lots of exercises that give you a function and ask for you to deduce the type of each one.

I have the following example. Please note this is not homework that I need to get done. I have the answer to this specific example and provide it below. Maybe someone can help me out in learning how to reason this kind of exercises.

The function:

h1 f g x y = f (g x y) x

The supposed type:

h1 :: (a -> b -> c) -> (b -> d -> a) -> b -> d -> c

Thanks!


I added 27 exercises here without solutions.

Some of them have solutions included here.
However, it is possible to know the type by using the GHCi command :t

  • 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-08T09:12:21+00:00Added an answer on June 8, 2026 at 9:12 am
    h1 f g x y = f (g x y) x
    

    So, taking the argument list from left-to-right:

    • f is a function applied to two arguments: the first is the result of (g x y) and the second is x
      • we don’t know what type the first argument is yet, so let’s call it a
      • we don’t know the second type either, so let’s call that b
      • we also don’t know the result type (so we’ll call that c), but we do know this must be the type returned by h1
        • now f is a function mapping a -> b -> c
    • g is a function applied to two arguments: the first is x and the second y
      • we know the first argument to g is the same as the second argument to f, so it must be the same type: we already labelled that b
      • the second argument to g is y, which we haven’t assigned a placeholder type yet, so that gets the next in sequence, d
      • g‘s result is the first argument to f, and we already labelled that a
        • so now g is a function mapping b -> d -> a
    • third argument is x, and as that’s the second argument to f, we’ve already labelled its type b
    • fourth argument is y, which is the second argument to g, so we’ve already labelled its type d
    • the result of h1 is the result of applying f to (g x y) x, as we said before, so it has the same type, already labelled c

    Although we worked through the argument list in order, the actual process of labeling, inferring and unifying types for each of those arguments was done by looking at the body of h1.

    So, my first bullet could be elaborated as:

    • f is the first argument to consider, so let’s look at the body of h1 (everything after the =) to see how it’s used
      • f (g x y) x means that f is applied to (g x y) x, so f must be a function
      • (g x y) is in parenthesis, which means whatever is inside those parentheses is being evaluated, and the result of that evaluation is an argument to f
      • x is just a simple argument to f, passed straight from h1‘s own argument list
      • so, f is a function taking two arguments

    If it helps read f (g x y) x, you can consider the equivalent expression in C-like notation would be f(g(x,y), x). Here, you can see right away that f and g are functions taking two arguments, that f‘s first argument is whatever g returns, etc.


    Note that the left-hand side of the expression, h1 f g x y, only gives one piece of type information by itself: h1 is a function on four arguments. The argument names themselves are just placeholders used in the right-hand side of the expression (the body of h1). The relative ordering of the arguments here just tells us how to call h1, but nothing about how h1 uses the arguments internally.

    Again, here’s a procedural-style equivalent (I’ll use Python so I don’t have to fill in any types):

    def h1(f, g, x, y):
        return f(g(x,y),x)
    

    this means exactly the same as

    h1 f g x y = f (g x y) x
    

    (with one caveat – partial application – that I suspect will only confuse matters further here).

    In both cases, the declaration (left of the = in Haskell, and before the : in Python) only tells us the function name and how many arguments it takes.

    In both cases, we can infer from the definition (right hand side in Haskell, the indented block after : in Python) that f and g are both functions on two arguments, that g‘s first argument is the same as f‘s second, etc. In Haskell, the compiler does this for us; Python will just complain at runtime if we call g with the wrong number of arguments, or it returns something f can’t use as a first argument.

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

Sidebar

Related Questions

Just stumbled upon propertyGrid and its awesome! However, i have one task that i
I have stumbled upon the following F77 yacc grammar: http://yaxx.cvs.sourceforge.net/viewvc/yaxx/yaxx/fortran/fortran.y?revision=1.3&view=markup . How can I
I'm hoping someone happens to have stumbled upon the following issue before. My Java
I am debugging some old ASP code and have stumbled upon the following error:
Im quite new to Java and i have stumbled upon the following problem. Im
I have once stumbled upon an open source project that implements the Google Chrome
Stumbled up one curiosity that i researched upon but found no exact answer whatsoever.
I have stumbled upon a strange behavior that I don't understand. I have to
I have stumbled upon a really odd bug with PHP's preg_replace function and some
I have stumbled upon an interesting problem/bug that I eventually solved, but the solution

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.