相关疑难解决方法(0)

RankNTypes和范围'forall'

这些有什么区别?

{-# LANGUAGE RankNTypes #-}

f :: forall a. a -> Int
f _ = 1

g :: (forall a. a) -> Int
g _ = 1
Run Code Online (Sandbox Code Playgroud)

特别是,为什么我会收到错误g ()

ghci> f ()
1
ghci> g ()
<interactive>:133:3:
    Couldn't match expected type `a' with actual type `()'
      `a' is a rigid type variable bound by
          a type expected by the context: a at <interactive>:133:1
    In the first argument of `g', namely `()'
    In the expression: g ()
    In an …
Run Code Online (Sandbox Code Playgroud)

haskell higher-rank-types

12
推荐指数
2
解决办法
686
查看次数

标签 统计

haskell ×1

higher-rank-types ×1