I'm trying to write a function in sml that takes a function and applies it to all elements in a list. If any element returns NONE then the entire function evals to NONE but if any element returns SOME v then that element is added to the accumulator.
The final return value is SOME of the acculumator. Right now I'm getting two errors.
- hw4.sml:93.21-95.67 Error: types of rules don't agree [tycon mismatch] earlier rule(s): 'Z option -> 'Y option this rule: 'Z option -> 'X list in rule: SOME v => ((all_answers_helper ) xs') v @ acc
- hw4.sml:90.5-95.67 Error: right-hand-side of clause doesn't agree with function result type [tycon mismatch]
expression: 'Z list -> 'Y list -> 'Y list option result type: 'Z list -> 'Y list -> 'Y list in declaration: all_answers_helper = (fn arg => (fn => ))
fun all_answers_helper f xs acc =
case xs of
[] => SOME acc
| x::xs' => case f x of
NONE => NONE
| SOME v => all_answers_helper f xs' v @ acc
But I have no idea what I'm doing wrong. All help is appreciated!