I'm trying to define a function that in python I would write:
def f(x: bool) -> float:
if x:
return 0.5
return 0.0
In lean 4 I tried writing this (this is the whole file):
def f (b : Bool) : Rat :=
match b with
| false => 0
| true => 0.5
But I get type errors:
failed to synthesize instance
OfNat Rat 0
failed to synthesize instance
OfScientific Rat
It seems to be having trouble turning the number literals I wrote into the type Rat
that I want. Probably I just need to invoke some conversion method on the literals to do the cast, but I don't know what that method is called and it's unfortunately basically impossible to google for the names of methods this basic.
Rat
doesn't actually exist and is being interpreted as the name of a constraint instead of the name of an actual type? In that case what is the type actually called. $\endgroup$