gpt4 book ai didi

haskell - 无法成为应用的仿函数的具体类型示例?

转载 作者:行者123 更新时间:2023-12-02 02:03:47 24 4
gpt4 key购买 nike

来自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 on r. In particular, there is no way how to define pure :: a -> (r, a) for an arbitrary r.

在这里,pure无法同时定义所有类型;但是,对于任何具体类型 T ,可以制作((,) T)一个应用程序。

问题:是否有一个具体仿函数(即不涉及类型变量)的示例,它是仿函数但不是应用程序?

最佳答案

我没有 50 声望在这里发表评论,所以我会尝试将其作为答案:

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?

来自无人居住类型的元组怎么样? (,) 无效

它是一个仿函数,对吗?

你能为它导出Applicative吗? pure 如何实现?

关于haskell - 无法成为应用的仿函数的具体类型示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44125484/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com