Question

Write a function isaset which takes a list of any equality type2 and returns true if the list is a set (each element appears exactly once). So, the type of isaset is ' 'a list -> bool.

Here are a few examples of expected behavior - isaset nil; * the empty set is definitly val it true : bool - isaset [foo,

Hints:

• Do not try for efficiency. A brute-force O(n2 ) solution is appropriate to this exercise. 3

• You might find it easier to develop an algorithm if you consider how to determine the list is not a set.

• A recursive helper function is needed; again, hide it inside let … in … end;

• isaset is recursive.

• Use appropriate pattern matching in your parameters.

• Trying hard, I found a use for defining a val inside the let … in … end;, but it was a bit contrived; don’t worry if your solution doesn’t have one.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

-fun notfound(x,[])=true

| notfound(x,b::y)

if x=b then false

else notfound(x,y);

val notfound = fn : ' ' a* ' ' a list ->bool

-fun isaset [ ]=true

| isaset (c::y)=

if notfound (c,y) then isaset(c::y)

else false;

val isaset =fn : ' ' a list -> bool

Add a comment
Know the answer?
Add Answer to:
Write a function isaset which takes a list of any equality type2 and returns true if the list is a set (each element app...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function isaset which takes a list of any equality type2 and returns true if...

    Write a function isaset which takes a list of any equality type2 and returns true if the list is a set (each element appears exactly once). So, the type of isaset is ' 'a list -> bool. Hints: • Do not try for efficiency. A brute-force O(n2 ) solution is appropriate to this exercise. 3 • You might find it easier to develop an algorithm if you consider how to determine the list is not a set. • A recursive...

  • Write a ML language function stripmin of type int list -> int list that will return...

    Write a ML language function stripmin of type int list -> int list that will return a list from which every instance of the lowest value has been removed. Hints: • Only stripmin itself should be visible at the top level; •You should have two recursive helper functions tucked away inside a let … in … end; structure • Also include a val to avoid having to pass a value that never changes to one of these functions. • Use...

  • c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc..   Please...

    c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc..   Please do all parts. previously I post 3 time for part1 ,2 and 3 but I can't make it into one complete program code. I even try to post a questions ask and post the 3 parts of code for experts to put it together. But experts said it's not enough information. please help... Thank you ! Program Objectives: Allow students to create arrays Allow...

  • Note: None of these functions should use cout. It is OK to use cout while debugging...

    Note: None of these functions should use cout. It is OK to use cout while debugging to check how your function is working, but your final submission should not contain cout in any function but main. Head ==== Name the source file for this section head.cpp. Write a function named "head" which takes an array of integers as an argument, and returns the first element in the array. Write a function named main which outputs the result of testing your...

  • How to write the insert, search, and remove functions for this hash table program? I'm stuck......

    How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...

  • Could someone please help me write this in Python? If time allows, it you could include...

    Could someone please help me write this in Python? If time allows, it you could include comments for your logic that would be of great help. This problem involves writing a program to analyze historical win-loss data for a single season of Division I NCAA women's basketball teams and compute from this the win ratio for each team as well as the conference(s) with the highest average win ratio. Background Whether it's football, basketball, lacrosse, or any other number of...

  • Requirements Print a range Write a bag member function with two parameters. The two parameters are...

    Requirements Print a range Write a bag member function with two parameters. The two parameters are Items x and y. The function should write to the console all Items in the bag that are between the first occurrence of x and the first occurrence of y. You may assume that items can be compared for equality using ==. Use the following header for the function: void print_value_range(const Item& x, const Item& y); print_value_range can be interpreted in a number of...

  • Objective: Write a program that implements the Game of Life cellular automata system invented by John...

    Objective: Write a program that implements the Game of Life cellular automata system invented by John Conway. 1. Create two game grids of size at least 50x50. These grid cells can be either Boolean or integer. In the following, I’ll refer to these as gridOne and gridTwo. 2. Set all cells in both grids to false. 3. Start by initializing gridOne. Allow the user to specify two different ways of initializing the grid: 1) by specifying a pattern file to...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

  • Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of...

    Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of physician-centered and collaborative communication. How is the caregiver’s role different in each model? How is the patient’s role different? Answer: Physical-centered communication involves the specialists taking control of the conversation. They decide on the topics of discussion and when to end the process. The patient responds to the issues raised by the caregiver and acts accordingly. On the other hand, Collaborative communication involves a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT