相关疑难解决方法(0)

制作(a,a)一个Functor

我怎样才能让(a, a)一个Functor不诉诸newtype

基本上我希望它像这样工作:

instance Functor (a, a) where
  fmap f (x, y) = (f x, f y)
Run Code Online (Sandbox Code Playgroud)

但当然,这不是表达它的合法方式:

Kind mis-match
The first argument of `Functor' should have kind `* -> *',
but `(a, a)' has kind `*'
In the instance declaration for `Functor (a, a)'
Run Code Online (Sandbox Code Playgroud)

我真正想要的是这样的类型级函数:( \a -> (a, a)语法无效).也许这是一个类型别名?

type V2 a = (a, a)
instance Functor V2 where
    fmap f (x, y) = (f x, f y)
Run Code Online (Sandbox Code Playgroud)

我认为这会奏效,但事实并非如此.首先我得到这个投诉:

Illegal instance declaration …
Run Code Online (Sandbox Code Playgroud)

haskell types functor typeclass

19
推荐指数
1
解决办法
3436
查看次数

标签 统计

functor ×1

haskell ×1

typeclass ×1

types ×1