langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
15
Task/Search-a-list/Standard-ML/search-a-list.ml
Normal file
15
Task/Search-a-list/Standard-ML/search-a-list.ml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
fun find_index (pred, lst) = let
|
||||
fun loop (n, []) = NONE
|
||||
| loop (n, x::xs) = if pred x then SOME n
|
||||
else loop (n+1, xs)
|
||||
in
|
||||
loop (0, lst)
|
||||
end;
|
||||
|
||||
val haystack = ["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"];
|
||||
|
||||
app (fn needle =>
|
||||
case find_index (fn x => x = needle, haystack) of
|
||||
SOME i => print (Int.toString i ^ " " ^ needle ^ "\n")
|
||||
| NONE => print (needle ^ " is not in haystack\n"))
|
||||
["Washington", "Bush"];
|
||||
Loading…
Add table
Add a link
Reference in a new issue