I am having a problem with pattern matching in an sml program.My code is this:
fun ff (arr, _, [], _) = []
|ff (arr, 0, (x::xs), ping_list) =ping_list
|ff (arr, K, (x :: xs), ping_list) =
(if Array.sub(arr, x)-1 < 1
then ff(arr, (K-1), xs, (ping_list@[x]))
else ff(arr, K, xs, (ping_list@[x])))
As you can see after going through the third case of the pattern matching it is possible for both K to be 0 and the third argument list to be [].In this case after running some tests it chooses the first pattern and returns [].
How can i control this?In a case of both K=0 and xs being empty i would like the second pattern to be executed and ping_list to be the result but i would also like to understand how corner cases like this are handled by sml.
Thank you in advance