相关疑难解决方法(0)

Bifunctor实例定义上的类型签名不匹配

我通过阅读《第一原理》(Allen&Moronuki)的《Haskell编程》一书来学习Haskell 。

在有关Monad Transformers,Functor和Applicative组成部分的练习中,它要求读者为以下类型编写Bifunctor实例

data SemiDrei a b c = SemiDrei a
Run Code Online (Sandbox Code Playgroud)

我的第一次尝试(编译)是

instance Bifunctor (SemiDrei a) where
    bimap f g (SemiDrei a) = SemiDrei a
Run Code Online (Sandbox Code Playgroud)

但是,看着它,在我看来我应该应该能够写,bimap f g = id因为最后一个参数不变或写了bimap f g x = x。两者都给我带来了编译错误,并且我希望有人可以向我解释为什么我不能bimap用这些较短的替代方法来表达,即为什么我必须指定(SemiDrei a)

我在Haskell 8.6.5上运行了此命令(如果相关)

尝试:ID

instance Bifunctor (SemiDrei a) where
    bimap f g = id

-- compile error message:
• Couldn't match type ‘a1’ with ‘b’
  ‘a1’ is a rigid type variable bound …
Run Code Online (Sandbox Code Playgroud)

haskell types bifunctor

4
推荐指数
2
解决办法
62
查看次数

标签 统计

bifunctor ×1

haskell ×1

types ×1