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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:28:23+00:00 2026-06-06T01:28:23+00:00

While studying for a Functional Programming exam, I came across the following questions from

  • 0

While studying for a Functional Programming exam, I came across the following questions from a previous test:

t2 = (\x -> \y -> \z -> (x y, x (x z)))

t3 = t2 (take 3 . reverse) mnr mnr

For t2, it is asked to determine the most general type of the statement. The answer appears to be:

(a -> a) -> a -> a -> (a,a)

I am able to find the answer by entering the statement into WinHugs, but how is this answer found? I understand from my previous post that it has something to do with lambda functions though other than that I am at a loss to explain what is going on here.

The second part of the question (t3) then applies two functions to two instances of the variable mnr. For mnr = [0,1,2,3,4,5,6] this results in:

([6,5,4],[4,5,6])

How does this work? The functions take and reverse are clear but how are they applied to the lambda functions in t2?

  • 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-06T01:28:24+00:00Added an answer on June 6, 2026 at 1:28 am

    Let’s start from the middle, at the result.

    (x y, x (x z))
    

    because x is being applied to things (y, z, and x z), we know it has the type (a -> ?) where the question mark represents an unknown type. Now, the result of x is being passed to x in x (x z), so its input type must be its output type:

    x :: a -> a
    

    Now, x is applied to y and to z, so they both must be of type a. x y and x (x z) are also both of type a (as that is x‘s return type), so t2 returns something of type (a, a).

    Putting this together with the type of its arguments (x, y, and z), we get that is has type

    (a -> a) -- x's type
    -> a -- y's type
    -> a -- z's type
    -> (a, a) -- the result type
    

    For you second question, let’s first look at what things are bound to what variables in t2‘s definition. The first argument is x, so in this case

    x = (take 3 . reverse)
    

    The next argument is y, so

    y = mnr
    

    Similarly for z,

    z = mnr
    

    The result will be (x y, x (x z)), so let’s evaluate this

    (x y, x (x z))
    = ((take 3 . reverse) mnr, (take 3 . reverse) ((take 3 . reverse) mnr))
    = (take 3 (reverse mnr), take 3 (reverse (take 3 (reverse mnr))))
    

    with this specific case of mnr = [0,1,2,3,4,5,6], we get

    = (take 3 (reverse [0,1,2,3,4,5,6]), take 3 (reverse (take 3 (reverse [0,1,2,3,4,5,6]))))
    = (take 3 [6,5,4,3,2,1,0], take 3 (reverse (take 3 [6,5,4,3,2,1,0])))
    = ([6,5,4], take 3 (reverse [6,5,4]))
    = ([6,5,4], take 3 [4,5,6])
    = ([6,5,4], [4,5,6])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While studying for a Functional Programming exam, I came across the following question from
While studying for the Zend PHP Exam I came across the following contradicting information:
I came across these terms recently, while studying a program. I got an idea
I came up with this example while studying mock exams for OCPJP certification, (from
While studying an implementation of Group signature I came across code where Group certificate
I have come across fluent API's while studying DSLs. I have searched a lot
While studying different programming languages, I recently hit upon Icon programming language . It
After studying the docs for a while, I came up with my first jQuery
While studying for the SCJP 6 exam, I ran into this question in a
While studying for the 70-433 exam I noticed you can create a covering index

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.