Write in SML: 3.areAllUnique - 10% areAllUnique function takes a list as input a
ID: 3757125 • Letter: W
Question
Write in SML:
3.areAllUnique - 10% areAllUnique function takes a list as input and returns true if every element in the list appears only once (i.e. unique in the list). areAllUnique returns false otherwise. Your function shouldn't need a recursion but should use functions "map"and "filter". You may need to define additional helper functions, which can be recursive. (Hint: Use the countInList from Assignment1 as a helper function) The type of the areAllUnique function should be 'a list ->bool Examples: > areAllUnique [1,3,4,2,5,0,10] true > areAllUnique [(1,21, 131,(4,51,[11 true > areAllUnique [ (1, "one"), (2,"two"),(1, "one")1 false > areAllUnique [ true > areAllUnique [1,2,3,4,1,7 falseExplanation / Answer
fun duplicated [] = false | duplicated (x::xs) = (List.exists (fn y => x = y) xs) orelse (duplicated xs)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.