Cannot unify types when using an existentially quantified type variable in two record fields
In the program below, the result type of fromInt
cannot be unified to the parameter type of toInt
, even though they are the same.
Would this be very complicated to implement?
import StdEnv
:: R = E.a: {fromInt :: Int -> a, toInt :: a -> Int}
f :: R -> Int
f r = r.toInt (r.fromInt 5)
Start = f {fromInt=id, toInt=id}
There is a workaround, so it's not really urgent:
:: R = E.a: {funs :: Funs a}
:: Funs a = {fromInt :: Int -> a, toInt :: a -> Int}
f :: R -> Int
f {funs=f=:{fromInt,toInt}} = toInt (fromInt 5)
Start = f {funs={fromInt=id, toInt=id}}