Why doesn't TypeSynonymInstances allow partially applied type synonyms to be used in instance heads?

后端 未结 3 1829
离开以前
离开以前 2020-12-01 08:11

I know that TypeSynomymInstances only allows fully applied type synonyms to be used in instance heads, but it seems like it would be handy if I could use paritally applied t

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 08:31

    Another issue with allowing partially applied type synonyms is that they would make type inference and instance selection essentially impossible. For example, suppose in the context of some program I wanted to use thingy at the type Int -> String -> Int -> (Int, String). thingy has type forall a b e. a -> b -> e a b, so we can unify a with Int and b with String, but if e is allowed to be a partially applied type synonym, we could have

    e = FuncSynonym (,)
    

    or

    e = FuncSynonym' Int (,) where type FuncSynonym' x f a b = x -> f a b
    

    or even

    e = Const2 (Int -> (Int, String)) where Const2 a x y = a
    

    The problem of type inference would become even worse than deciding equality of functions; it would require considering all functions with specified output on a particular input, or similar more complicated problems (imagine simply trying to unify a b with Int).

提交回复
热议问题