Type abstraction in GHC Haskell

六月ゝ 毕业季﹏ 提交于 2019-12-01 04:31:12

This might be a GHC bug. I can not see how this GHC behavior makes any sense.

This issue has nothing to do with type families, but it seems to arise from ambiguous types and typeclass constraints.

Here is a MCVE for the same issue.

{-# LANGUAGE AllowAmbiguousTypes    #-}
{-# LANGUAGE RankNTypes             #-}
{-# LANGUAGE TypeApplications       #-}

class C a where
   getInt :: Int

instance C Char where
   getInt = 42

f :: (forall a. C a => Int) -> Bool
f x = even (x @ Char)

g :: (forall a. C a => Int) -> Bool
-- g = f               -- fails
-- g h = f h           -- fails
-- g h = f getInt      -- fails
g _ = f 42             -- OK

It seems that f can not be called with any argument that actually exploits the constraint.

This is by design. It seems there is no way around using Proxys for now: https://ghc.haskell.org/trac/ghc/ticket/15119.

Edit Jul 2019: There's now a GHC proposal for this!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!