在Haskell中采用简单的身份功能,
id :: forall a. a -> a
Run Code Online (Sandbox Code Playgroud)
鉴于Haskell据称支持impregicative多态性,我应该能够通过类型归属"限制" id
到类型似乎是合理的(forall a. a -> a) -> (forall b. b -> b)
.但这不起作用:
Prelude> id :: (forall a. a -> a) -> (forall b. b -> b)
<interactive>:1:1:
Couldn't match expected type `b -> b'
with actual type `forall a. a -> a'
Expected type: (forall a. a -> a) -> b -> b
Actual type: (forall a. a -> a) -> forall a. a -> a
In the expression: …
Run Code Online (Sandbox Code Playgroud) 我正在玩van Laarhoven镜头并遇到一个问题,其中类型检查器拒绝了et-reduced形式的良好类型的功能:
{-# LANGUAGE RankNTypes #-}
import Control.Applicative
type Lens c a = forall f . Functor f => (a -> f a) -> (c -> f c)
getWith :: (a -> b) -> ((a -> Const b a) -> (c -> Const b c)) -> (c -> b)
getWith f l = getConst . l (Const . f)
get :: Lens c a -> c -> a
get lens = getWith id lens
Run Code Online (Sandbox Code Playgroud)
上面的类型检查,但如果我eta减少get
到
get :: Lens …
Run Code Online (Sandbox Code Playgroud)