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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:30:20+00:00 2026-05-18T23:30:20+00:00

I have this bit of code: fun foldr2(f, x::xs) = if xs = []

  • 0

I have this bit of code:

fun foldr2(f, x::xs) =
    if xs = [] then
      x
    else
      f(x, foldr2(f, xs))

With the type signature

(''a * ''a -> ''a) * ''a list -> ''a

Looks pretty straight-forward, it takes a function that works over equality types and a list of equality type as arguments, because of the xs = [] comparison. However, for some reason it works on input such as (op +, [2.3, 2.7, 4.0]), when in SML/NJ reals are not an equality type. Can anyone help me shed some light on why this magic occurs?

  • 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-18T23:30:21+00:00Added an answer on May 18, 2026 at 11:30 pm

    I believe it’s to do with the magical way in which + is overloaded for reals. To me, this almost verges on being a compiler bug, although I would have to look at the SML97 definition to see exactly what the correct behaviour is meant to be. The overloading over + is something of a nasty dark corner in SML, IMHO.

    For example, if you define a function that is of type real * real -> real and pass that as an argument to foldr2 you get the type error you were expecting:

    fun f (x : real * real) = 134.5
    foldr2 (f, [1.4, 2.25, 7.0])
      stdIn:8.1-8.29 Error: operator and operand don't agree [equality type required]
    

    You can even induce the type error if you just add a type annotation to op +, which basically led me to the conclusion that it is the overloading of + that is causing the mysterious effect.

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

Sidebar

Related Questions

I have a bit of code that looks like this: text = reg.Replace(text, new
I have this bit of code <input type=image src=/wp-content/themes/happy/images/add-to-cart.png name=Buy class=wpsc_buy_button id=product_<?php echo wpsc_the_product_id();
I have this bit of code I found on the web at the end
Well, I have this bit of code that is slowing down the program hugely
I have a table that looks a bit like this actors(forename, surname, stage_name); I
I have a database that contains a table that looks a bit like this:
I have this bit of code def build_tree_base(blocks, x, y, z): indicies = [
I have this little bit of code: using System; using System.Web.Mvc; public class SecureFilter
i have this bit of code: <?php $file = file_get_contents('http://example.com'); preg_match_all(/<a href=(.*?links.*?)>.*?<\/a>/i, $file, $a);
I have this bit of code: int main() { String s1; // s1 ==

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.