I am trying to infer the type of the following expression:
let rec fix f = f (fix f)
which should be given the type (a -> a) -> a
After using the bottom up algorithm (described in generalizing hindley-milner type inference algorithms) with the added rule below:
a1, c1 |-BU e1 : t1 B = fresh var
---------------------------------------------------------
a1\x, c1 U {t' == B | x : t' in A} |-BU let rec x = e1 : t
i am left with the following type: t1 -> t2
and the following constraints:
t0 = fix
t1 = f
t2 = f (fix f)
t3 = f
t4 = fix f
t5 = fix
t6 = f
t3 = t1
t3 = t4 -> t2
t5 = t0
t5 = t6 -> t4
t6 = t1
I cant see how these constraints can be solved such that i am left with the type (a -> a) -> a
. I hope it is obvious for someone to see were i am going wrong.
let rec
should be simplylet
, otherwise you're just defining a functionrec :: ((a -> b) -> a) -> (a -> b) -> b
. – Ptharien's Flame