相关疑难解决方法(0)

什么是AllowAmbiguousTypes以及为什么在这个"forall"示例中需要它?

代码

{-# LANGUAGE ScopedTypeVariables, TypeApplications #-}

-- I know this particular example is silly.
-- But that's not the point here.
g :: forall a . RealFloat a => Bool
g = True

main :: IO ()
main = print (g @Double)
Run Code Online (Sandbox Code Playgroud)

无法在GHC 8.0上编译并出现错误

• Could not deduce (RealFloat a0)
      from the context: RealFloat a
        bound by the type signature for:
                   g :: RealFloat a => Bool
        at app/Main.hs:3:6-35
      The type variable ‘a0’ is ambiguous
    • In the ambiguity check …
Run Code Online (Sandbox Code Playgroud)

haskell types ghc

12
推荐指数
1
解决办法
1889
查看次数

标签 统计

ghc ×1

haskell ×1

types ×1