类型不像建议的那样多态
Type not as polymorphic as suggested
我正在尝试为以下数据类型创建一个 Functor 实例:
data Event t a = Event { runEvent :: t -> ([a], Event t a) }
instance Functor (Event t) where
fmap :: (a -> b) -> Event t a -> Event t b
fmap f e = Event go
where
go t = (fmap f x, e')
where
(x, e') = Event.runEvent e t
但是编译失败并出现以下错误:
E FRP.fr:11: type `γ` is not as polymorphic as suggested in
the annotation where just `β` is announced.
E FRP.fr:11: type error in expression go
type is : ([γ],Event α β)
expected: ([γ],Event α γ)
我尝试添加一些类型注释来泛化 let 绑定,但这没有用。
所以我们有传入e::Event t a
将 runEvent
应用于 e
给我们在元组的第二个元素中仍然是 Event t a
,不是吗?但它应该是 Event t b
,对吧?
(该错误非常令人困惑,因为它会出现 resp. go
并使用在类型检查中使用的新类型变量 go
)
我正在尝试为以下数据类型创建一个 Functor 实例:
data Event t a = Event { runEvent :: t -> ([a], Event t a) }
instance Functor (Event t) where
fmap :: (a -> b) -> Event t a -> Event t b
fmap f e = Event go
where
go t = (fmap f x, e')
where
(x, e') = Event.runEvent e t
但是编译失败并出现以下错误:
E FRP.fr:11: type `γ` is not as polymorphic as suggested in
the annotation where just `β` is announced.
E FRP.fr:11: type error in expression go
type is : ([γ],Event α β)
expected: ([γ],Event α γ)
我尝试添加一些类型注释来泛化 let 绑定,但这没有用。
所以我们有传入e::Event t a
将 runEvent
应用于 e
给我们在元组的第二个元素中仍然是 Event t a
,不是吗?但它应该是 Event t b
,对吧?
(该错误非常令人困惑,因为它会出现 resp. go
并使用在类型检查中使用的新类型变量 go
)