0
fun first_answer(my_f:('a -> 'b option)) : 'a list -> 'b =
let
fun help(_a:'a list) : 'a =
(((List.map valOf)o(List.filter isSome)o(List.map my_f)) _a)
in
help
end;

Error: syntax error: replacing WILD with SEMICOLON

Something with that _a is messing it up..... The error is linked to the last usage of _a

I am not getting very far, and I've rearranged the logic many ways already. As you can see the first_answer returns takes a function and returns a function. This is what I am doing here and I am following the types as far as I know. There is probably something simple that I am not seeing.

1 Answer 1

4

It's simple indeed: an identifier cannot start with an underscore. So _a is parsed as if you had written _ a, in accordance with the usual maximal munch rule for lexical syntax.

Edit: Extra tip: Your function does not have the type 'a list -> 'b, because help returns a list of 'bs, not a single value of type 'b. Moreover, as written, it can be implemented more easily as

fun first_answer f xs = List.mapPartial f xs

or, in fact,

val first_answer = List.mapPartial
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.