0

I have the following examples and they do not work even though the types do matchup with each other

- isSome;
val it = fn : 'a option -> bool


- SOME;
val it = fn : 'a -> 'a option
- val my_converter = (fn x => if x = 5 then SOME x else NONE);
val my_converter = fn : int -> int option

Both SOME and my_converter return an option but when I do the following

- fn x => isSome o SOME x;
stdIn:19.9-19.24 Error: operator and operand don't agree [tycon mismatch]
  operator domain: ('Z option -> bool) * ('Y -> 'Z option)
  operand:         ('Z option -> bool) * 'X option
  in expression:
    isSome o SOME x

I get a type error why?

melpomene
  • 84,125
  • 8
  • 85
  • 148
Har
  • 3,727
  • 10
  • 41
  • 75
  • Since `isSome o SOME` returns `true` for all input, I don't see the motivation of ever using it. – John Coleman May 01 '17 at 11:41
  • That is the simplest example of builtins I can use to demonstrate a more general pattern of how do you combine isSome with a conditional based SOME/NONE pair – Har May 01 '17 at 11:43

1 Answers1

1

The error message is telling you that o wants a function operand but what it actually gets is an option. This is because isSome o SOME x parses as isSome o (SOME x), which makes no sense.

You can fix this by writing

(isSome o SOME) x

instead.

melpomene
  • 84,125
  • 8
  • 85
  • 148