Created
April 2, 2015 15:35
-
-
Save chrisamaphone/c2c43150028c434d2821 to your computer and use it in GitHub Desktop.
continuation-passing function that returns the value of a key in a table as a (key,value) list, and also the table with that key removed, if it exists.
This file contains 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
(* lookupSplit : ''a -> (''a * 'b) list -> ('b * (''a * 'b) list) option *) | |
fun lookupSplit id table = | |
let | |
fun lookupSplit' id nil cont = NONE | |
| lookupSplit' id ((k,v)::table) cont = | |
if k = id then SOME (v, cont table) | |
else lookupSplit' id table (fn suffix => cont ((k,v)::suffix)) | |
in | |
lookupSplit' id table (fn x => x) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment