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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:06:22+00:00 2026-06-11T22:06:22+00:00

The below code is just a kind of prototype. What I want to know

  • 0

The below code is just a kind of prototype. What I want to know is why it fails to compile.

fun test(list) = 
    let 
    fun inner(list) = 
    let
        val from = #1(hd(list))
        in
        if null(tl(list)) = false then innerinner(tl(list),from)
        else false
        end 
    fun innerinner(list,from) = 
        if #2(hd(list)) = from then true
        else if null(list) = false then innerinner(tl(list),from)
        else false
    in
    inner(list)
    end;

The error messages are:

test.txt:7.34-7.44 Error: unbound variable or constructor: innerinner
test.txt:3.2-9.6 Error: unresolved flex record
(can't tell what fields there are besides #1)
test.txt:10.2-13.13 Error: unresolved flex record
(can't tell what fields there are besides #2)

uncaught exception Error
raised at: ../compiler/Toplevel/interact/evalloop.sml:66.19-66.27
....

I am a kind beginner of ML programming. Could anyone teach me what is wrong?

  • 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-11T22:06:23+00:00Added an answer on June 11, 2026 at 10:06 pm

    You have quite a few things going on here. If we first look at the errors you are getting.

    1. unbound variable or constructor: innerinner

      In sml you can’t “use” stuff before it has been declared. It is easily fixed in your case by
      swapping the function declarations around, and thus declaring innerinner before inner.

      If you ever end up in a case where you want to for example declare two mutually recursive
      functions, then this is not an option. In this case you would have to use the keyword and.

    2. unresolved flex record

      This is a bit more complicated. It is a type error and has something to do with the fact
      that tuples are represented as records internally (I would recommend you go read about
      it). Thus when you don’t supply enough information, the type system will complain.

      I think this QA explains it quite good. In summary, you can’t have unbounded tuples
      and thus you need to make it clear to the type system how many elements it contains. This
      could be done by explicitly type annotating the function declaration.
      However in general you ought to use pattern matching instead, as often as feasible.

    In general you should always use pattern matching rather than tuple selectors (#1, #2, …), or list selectors (hd or tl). You just saw why tuple selectors can be “bad” but using list selectors without testing whether or not the list is empty first will give you runtime errors (exceptions).

    Putting in such test cases in your code will “blow it up” and make it messy to read. But if you use pattern matching instead you will have some nice clear cut cases in your function definition.
    Also often you will tend to writer less code (in my opinion).

    Btw, you don’t need to put parentheses around single arguments to functions, such as you main definition of the test function.

    All in all your function could look something like this:

    fun test list =
    let
      fun innerinner ((x1, x2)::xs,from) =
          if x1 = from then true
          else innerinner(xs,from)
        | innerinner ([], from) = false
    
      fun inner ((x1, x2)::xs) = innerinner(xs,x1)
        | inner [] = false
    in
      inner(list)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get output like 0 1 , but the code below just
I'm just looking to optimize the code below. It works, but I want to
i use below code - Just try again. - to prevent deadlock. it seems
I am just learning Perl's comparison operators. I tried the below code :- $foo=291;
First, I just wanted to say that the below code is working in reality.
Just wondering about this code below... when I turn off my internet connection and
I changed the code shown below into ARC compatible. I just changed it as
I have the code block below, I deleted all unnecessary parts, just left the
I grabbed this code form JCarousel and just trying to understand these lines below.
I can't get this code to work. Declared playpauseButton just above the given below

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.