Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bhargavg/812e7590c52193d007e4396f35fd7212 to your computer and use it in GitHub Desktop.
Save bhargavg/812e7590c52193d007e4396f35fd7212 to your computer and use it in GitHub Desktop.
SML - Failing to compile
(* Problem: Write a function that returns true
* when invoked with list of alternate 1's and 2's
*
* Example:
* matcher [1,2,1,2]
* matcher [1,2,1]
* matcher [1,2]
* matcher [1]
*
* all of the above should return true
*)
fun match_one (xs, f) =
case xs of
[] => true
| 1::xs' => f (xs', match_one)
| _ => false
fun match_two (xs, f) =
case xs of
[] => true
| 2::xs' => f (xs', match_two)
| _ => false
fun matcher xs = match_one (xs, match_two)
@bhargavg
Copy link
Author

This solution doesn't work.

Both match_one and match_two won't pass the type check, because there is no way to deduce the type of argument f in both functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment