Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This problem is supposed to be coded in Standard ML, I tried this fun exists (x,

ID: 3883348 • Letter: T

Question

This problem is supposed to be coded in Standard ML, I tried this

fun exists (x, L) = if null L then false else if x = hd(L) then true else exists(x, tl(L));

but I get this error 'stdIn:27.52 Warning: calling polyEqual'.

1. exists -15% This function should return true if the first argument is a member of the second argument and have type (''a''a list) ->bool. Explain in a comment why the typeis (''a''a list) ->bool and not ('a'a list) bool Note: this function is not required to be tail-recursive. Examples exists (1,1) false > exists (1,(1,2,31) true exists ((1],1]1) true > exists ((1), [[3),[5]]); false exists "c","b","c","z"]): true

Explanation / Answer

Hi,
You are going in the right direction,
here is the code, that will work with the same logic as yours
fun exists_in (item: ''int, mylist:''list) =
if null mylist //null check
then false
else if (hd mylist) = item // hd list gives first items
then true
else exists_in(item, tl mylist) // tl gives all but 1st element
exists_in(1,[1,2,3]);
Thumbs up if this was helpful, otherwise let me know in comments. Good Day.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote