let min a b = if cmp a b <= 0 then a else b