一个没有成为应用的函子的具体类型例子? [英] Concrete Type Example of a Functor that Fails to be an Applicative?
问题描述
从不适用的函子:
一个类型构造函数,它是一个Functor而不是一个Applicative。一个简单的例子是一对:($,$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b
但是,如何定义
Applicative
实例,而不对r
施加额外限制。特别是,如何定义pure :: a - >是没有办法的。 (r,a)
为任意r
。
这里,纯粹
无法一次为所有类型定义;然而,对于任何具体类型 T
,可以使((,)T)
问题:是否存在一个具体仿函数(即,没有涉及的类型变量)的例子,它是一个仿函数而不是应用程序?
我没有50个评论,所以我会尽力回答:然而,对于任何具体类型T,可以使((,)T)成为一个应用。
$ b
...
数学中有一个定理,至少2个元素可以被制成一个monoid。因此,对于任何具体类型T,它原则上可以成为Monoid的成员,然后原则上可以适用。这个推理有什么问题?
那么这个无人居住类型的元组呢? (,)Void
它是 Functor
,对吗?
您可以为它导出 Applicative
吗? 纯粹
如何实现?
From functors that are not applicatives:
A type constructor which is a Functor but not an Applicative. A simple example is a pair:
instance Functor ((,) r) where fmap f (x,y) = (x, f y)
But there is no way how to define its
Applicative
instance without imposing additional restrictions onr
. In particular, there is no way how to definepure :: a -> (r, a)
for an arbitraryr
.
Here, pure
fails to be definable for all types at once; however, for any concrete type T
, one can make ((,) T)
an applicative.
Question: Is there an example of a concrete functor (i.e., no type variables involved) that is a functor but not an applicative?
I don't have 50 reputation to comment here, so I'll try to do it as an answer:
however, for any concrete type T, one can make ((,) T) an applicative.
...
There's a theorem in mathematics that any collection with at least 2 elements can be made into a monoid. So for any concrete type T, it could in principle be made a member of Monoid, and then could in principle be made Applicative. What's wrong with this reasoning?
What about the tuple from the uninhabited type? (,) Void
It is a Functor
,right?
Could you derive Applicative
for it? How would pure
be implemented?
这篇关于一个没有成为应用的函子的具体类型例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!