fun improve x y = (y+x/y)/2.0; fun satis x y = abs(y*y-x) < 0.001; fun until p f x = if p x then x else until p f (f x); fun sqrt x = until (satis x) (improve x) x;