Last active
October 18, 2016 04:17
-
-
Save bhargavg/812e7590c52193d007e4396f35fd7212 to your computer and use it in GitHub Desktop.
SML - Failing to compile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This solution doesn't work.
Both
match_one
andmatch_two
won't pass the type check, because there is no way to deduce the type of argumentf
in both functions.