I've been given the following code and I've been asked to determine the type.
exception Break;
fn f => fn a => fn b =>
(f(raise Break)
handle Break => if (f a) then a else raise Break)
handle Break => if not(f a) then a else b;
I know that this function takes in f, a and b and outputs a in all instances so it must be equivelant to:
fn f => fn a => fn b => a
which has the type:
'a -> 'b -> 'c -> 'b
because 'if( f a)' we can derive that 'a must be a function that takes in type 'b and outputs a boolean otherwise it wouldn't work.
('b->bool) -> 'b -> 'c -> 'b
re done so 'a is the beginning:
('a->bool) -> 'a -> 'b -> 'a
is what I get from this for my final answer. However when I type it out in the command prompt I get the following type:
(bool->bool) -> bool -> bool -> bool
what am I missing? At what point does 'a and 'b (from my final type evaluation) specialize to bool?