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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:53:38+00:00 2026-06-01T01:53:38+00:00

I want to make a function in standard ml that checks if a tree

  • 0

I want to make a function in standard ml that checks if a tree is complete or not, the function somehow works, but its giving me the wrong type and a warning of non-exhaustive cases

The tree code:

datatype 'data tree = 
  EMPTY
| NODE of 'data tree * 'data * 'data tree;

fun isComplete EMPTY = true
  | isComplete (NODE(x, y, z)) = if (x = EMPTY andalso z <> EMPTY) orelse (x <> EMPTY andalso z = EMPTY) then false else true;

Now the above function’s type is: ''a tree -> bool but the required type is 'a tree -> bool

The warning I’m having is:

stdIn:169.8 Warning: calling polyEqual
stdIn:169.26 Warning: calling polyEqual
stdIn:169.45-169.47 Warning: calling polyEqual
stdIn:169.64-169.66 Warning: calling polyEqual
stdIn:124.1-169.94 Warning: match nonexhaustive
          NODE (x,y,z) => ...

What is the problem I’m having?

EDIT:

Thanks to Michael, I fixed the code and now it works:

- fun isComplete EMPTY = true
    | isComplete (NODE(EMPTY, _, EMPTY)) = true
    | isComplete (NODE(NODE(x, y, z), _, NODE(a, b, c))) = true
    | isComplete (EMPTY, _, NODE(x, y, z)) = false
    | isComplete (NODE(x, y, z), _, EMPTY) = false;
  • 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-01T01:53:39+00:00Added an answer on June 1, 2026 at 1:53 am

    The ''a tree -> bool type indicates that a is an equality type: it must be a type that supports testing with equals. Since you are using = and <> to test x and z, the tree data must support equality (even though you’re not doing anything interesting with the values). This is the root of the polyEqual warning.

    The nonexhaustive match warning is more puzzling. When I paste your datatype and function definitions into Moscow ML, I do not get a warning. I don’t think I’d worry about it too much, as I’d expect fixing the type to also take care of the warning.

    To get the desired type 'a tree -> bool, I’d suggest getting rid of the if in favor of pattern matching. E.g.:

    fun isComplete EMPTY = true
      | isComplete (NODE(EMPTY, _, EMPTY)) = true
      | isComplete (NODE(EMPTY, _, NODE(x,y,z))) = false
      | ... (* fill out the rest of the cases *)
    

    I’ll leave it to you to figure out the full set of cases, as this looks like homework.

    Incidentally, I don’t think your test for completeness is correct. Consider what happens when neither subtree is EMPTY: you call the tree complete without considering the contents. This doesn’t have anything to do with the warnings you’re seeing, though.

    • 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 function for a new datatype in Standard ML, the
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
I'm trying to make a sliding panel using .animate function because I want it
I want to make sure that a set of functions have the same signature
I want to make a program that pulls objects from a sql database and

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.