fun findz
(f: int -> int): int = loop (0) where {
fun loop (i: int):<cloref1> int =
if f (i) = 0 then i else loop (i+1)
}
val poly1 = lam (x: int): int => (x + 10) * (x - 11)
val z1 = findz (poly1)
val () = printf ("z1 = %i\n", @(z1))
typedef ans_t = int
typedef cont (a: t@ype) = a -<cloref1> ans_t
val kpoly1 =
lam (x: int, k: cont int): ans_t => k ((x + 10) * (x - 11))
fun kfindz
(kf: (int, cont int) -> ans_t, k: cont int): ans_t = let
fun kloop (i: int, k: cont int):<cloref1> int =
kf (i, lam res => if res = 0 then k (i) else kloop (i+1, k))
in
kloop (0, k)
end
val K0 = lam (res: int): ans_t =<cloref1> res
val kz1 = kfindz (kpoly1, K0)
val () = printf ("kz1 = %i\n", @(kz1))
implement main () = ()