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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:44:09+00:00 2026-05-19T22:44:09+00:00

I have a midterm coming up next week and I was just going over

  • 0

I have a midterm coming up next week and I was just going over the sml notes provided in class. I came across a currying example and I was not sure exactly how it worked.

It is a simple function which computes the power of a number. Here is the function definition:

fun pow 0 n = 1 | pow k n = n*pow(k-1)n

I’m not sure how this function works when we pass it the following arguments:

val x = pow 2 2

This is the way I see it:

=2*pow(1)2
=2*(2*pow(0)2)2
=2*(2*(1)2)2) 

The result we should be getting is four but I don’t see how we get this result from the steps I have carried out above.

Help Please. Thank-You.

  • 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-19T22:44:10+00:00Added an answer on May 19, 2026 at 10:44 pm

    Ah, Standard ML of New Jersey, how I miss thee…

    Anyway, let me go through this step by step. Remember that currying, unlike the dinner in front of me (which incidentally is a curry dish), is basically a way of dealing with only one argument at a time to return a new function. With that in mind, apply the first 2 to the given function. Since only one pattern matches, you now have a new function — let’s call it “curry”:

    curry n = n * pow 1 n
    

    Note that you now have an “inner” version of the pow function to address. Doing so, again, one pattern matches. Let’s call this inner curried function “rice”:

    rice n = n * pow 0 n
    

    And one more, “shrimp” — but this time, the other pattern matches:

    shrimp n = 1
    

    The recursion has terminated here, so you have:

    rice n = n * 1
    curry n = n * (n * 1)
    

    Now, use the second 2 in your original pow 2 2 with the new curry function:

    curry 2 = 2 * (2 * 1)
    

    which of course is 4.

    I highly doubt SML names the curried functions in this way, but I hope this does help to understand the concept. I take no responsibility if it also makes you hungry.

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

Sidebar

Related Questions

Have you ever had to justify the choice over using .NET instead of Java
I have the following tables in my database. The tables midterm and finalterm contain
Have just started to get into CakePHP since a couple of weeks back. I
I've got an app that is just over 1yr old but it still evolving
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have just started converting an existing job tracking system into an ASP.NET MVC application.
We just got a midterm project today for my operating systems course, we are
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =

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.