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

  • Home
  • SEARCH
  • 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 6916625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:37:38+00:00 2026-05-27T09:37:38+00:00

I am working on a SML programming assingment for class and stuck on a

  • 0

I am working on a SML programming assingment for class and stuck on a question. The question is:
“Write an ML function that uses map, foldr, or foldl to compute the intersection of a nonempty list of sets.Here you may assume that sets are denoted as lists. For this problem, you may use auxilary named functions (e.g., isMember). Hint: A nonempty list of sets contains at least one set.”

This is what I have so far can anyone point me in the right direction I am fairly new to SML?

fun member(x,[]) = false
|   member(x,L) =
        if x=hd(L) then true
        else member(x,tl(L));

fun intersect(L1,L2) = if tl(L1) = [] then L1 
else if member(hd(L1),L2) = true then L1
else intersect(tl(L1),L2);

fun combine(L1) = if tl(L1) = [] then hd(L1)
else
    foldr intersect [] L1;

What I want the code to do is start off by executing the combine function with a lists of lists. It checks if there is only one list (i.e. tl(L1) = []) and if it is true then just print the first list. If its false I want to call the foldr function that then calls the intersect function. In theory during the foldr function I want it to check the first list and second list and only keep what values are the same, then check the next list to those kept values and keeping doing this until it has checked every list. After that is done I want it to print each value that was in each list (i.e. intersection of sets).

I know my member function works and the combine function does what its supposed to do, my QUESTION is, what is wrong with the intersection function and can someone explain what the intersection should be doing?

I obviously don’t want the straight up answer, that’s not what I am here for. I need help to get on track for the right answer.

  • 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-27T09:37:38+00:00Added an answer on May 27, 2026 at 9:37 am

    Here is my working answer!

    fun member(x,[]) = false
    |   member(x,L) =
            if x=hd(L) then true
            else member(x,tl(L));       
    
    fun intersect([],[]) = []
    | intersect(L1,[]) = []
    | intersect(L1,L2) = if member(hd(L2), L1) then hd(L2)::intersect(L1, tl(L2))
        else intersect(L1, tl(L2));
    
    fun combine(L1) = if L1 = [] then []
    else if tl(L1) = [] then hd(L1)
    else foldr intersect (hd(L1)) (tl(L1));
    

    Here are some test cases ran.

    combine([[1,2],[1,3],[1,4]]);
    val it = [1] : int list
    combine([[1,2,3],[1,8,9,3],[1,4,3,8,9]]);
    val it = [1,3] : int list
    combine([[1,2,3,8,9],[1,8,9,3],[1,4,3,8,9]]);
    val it = [1,3,8,9] : int list
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A couple of my friends are working on a simple recursive function in SML,
I have been looking for an elegant way to write a function that takes
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a project that parses a log of events, and then updates a
Currently, I'm working on representing an AST tree I have, written in SML, in
Working on calling a C function from my asm project. I'm trying to push
Working on an extension that use the new experimental devtools apis. How do you
Working demo CLick $(document).ready(function(e) { $('span#pijlr, span#pijll').show(); $('#gallery').css('overflow','hidden'); $('span#pijlr').click(function(e) { if (!$('#gallcont').is(':animated')) { var
Working with a Lucene index, I have a standard document format that looks something
Working in Java: I have a JFrame class, and separate classes for my two

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.