-4

I want to get an int that indicates the number of repeated values in the list of int

 fun iretate_list (fx : int list, tn : int) = 
   if null fx 
   then [] 
   else
         let val count = 0
         in
             if hd fx = tn then count + 1 :: [] else iretate_list(tl fx, tn)
         end

1 Answers1

0

If the element is found, the result is [count + 1], and count + 1 is 0 + 1, which is 1, so ...

The result should be an int, not a list, so start with changing your base case to 0 – not [].
You should also not stop when you find a match, but recurse and do something with the result.

fun iterate_list ([], tn) = 0
  | iterate_list (x::xs, tn) = if x = tn
                               then <something involving recursion on xs>
                               else iterate_list (xs, tn)

Some parts left as an exercise.

molbdnilo
  • 64,751
  • 3
  • 43
  • 82