type 'a pair = Pair of 'a * 'a

class H 'a { h : 'a -> int }

instance ['a] H 'a => H 'a pair { h = fun x -> 0 }

instance H int { h = fun x -> x }

instance H char { h = fun x -> 1 }

let fst = fun x -> match x with Pair (a, _) -> a

let rec ['a] [H 'a] (f : 'a -> int) = fun x -> g x

and g = fun x -> fst (Pair (f (Pair (x, x)), h x))

let main = Pair (f 0, f 'a')
