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

The Archive Base Latest Questions

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

I want to make a function for a new datatype in Standard ML, the

  • 0

I want to make a function for a new datatype in Standard ML, the datatype is called intnest, defined as the following:

datatype intnest = 
  INT of int
| LIST of intnest list;

and I want to make a function that adds all the integers in the intlist, I tried the following code:

fun addup (INT n) = n
  | addup (LIST x::xs) = x + addup(xs);

What am I doing wrong?

EDIT:

I also tried the following:

fun addup (INT n) = n
  | addup (LIST x::xs) = addup(x) + addup(xs);

so that x is of type INT so the first option returns its int value and the addup(xs) is a recursive call to return the same second option.

Also tried the following:

fun addup (INT n) = n
  | addup (LIST []) = 0
  | addup (LIST x::xs) = addup(x) + addup(LIST xs);

but I get the following error:

stdIn:146.4-151.50 Error: parameter or result constraints of clauses don't agree [tycon mismatch]
  this clause:      intnest list -> 'Z
  previous clauses:      intnest -> 'Z
  in declaration:
    addup =
      (fn INT n => n
        | LIST nil => 0
        | :: (<pat>,<pat>) => addup <exp> + addup <exp>)
stdIn:151.25-151.50 Error: operator and operand don't agree [tycon mismatch]
  operator domain: intnest
  operand:         intnest list
  in expression:
    addup x
  • 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-31T22:30:10+00:00Added an answer on May 31, 2026 at 10:30 pm

    First, there is a syntax error in the LIST case; get rid of the of. You’ll want the case to look like addup (LIST(x::xs)) = ....

    More substantially, there are conceptual problems in addup. The desired type of addup appears to be intnest -> int. It’s thus necessary to ensure that addup is always applied to intnest values and returning int values.

    Now consider the type of the elements of the list x::xs. You defined it as LIST of intnest list, so x is an intnest. But in addup, you treat x as an integer.

    Along the same lines, xs is a intnest list, but that’s not an intnest, which is what you’re treating it as in addup(xs). Your revised version addresses the problem with x, but not that with xs. You need to make an intnest from xs using LIST, which means you’ll need to use addup(LIST xs).

    Finally, you are missing a case. What happens when you have LIST []?

    The third version doesn’t work because you’re missing needed parentheses. The compiler is telling you that you’re using a intnest list as one of the cases (the :: case). That is, it sees LIST x::xs as (LIST x) :: xs.

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

Sidebar

Related Questions

I want to make a function that is always running in xcode similar to
Let's imagine I want to make a templated function that returns the first element
I want to make a constructor function that creates a documentElement object. As an
i have 6 edittext boxes i want to make a function for that 6
I have a function that does xml parsing. I want to make the function
I want to make a function called 'load' which imports definitions of functions from
I often want to make a multiline function call and reduce it down to
I want to make a link call a Javascript function through the onclick event
I want to make some C++ program and I'm using function popen here to
Say, i have a function which returns a reference and i want to make

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.