gpt4 book ai didi

haskell - 自然变换中的仿函数在哪里?

转载 作者:行者123 更新时间:2023-12-02 21:29:34 25 4
gpt4 key购买 nike

自从我看到 definition of natural transformations 以来,我的脑海里一直浮现着这个问题。在 Edward Kmett 的旧类别附加包中:

-- | A natural transformation between functors f and g.
type f :~> g = forall a. f a -> g a

但现在阅读 Stephen Diehl 在 adjunctions 上的博客文章,我发现这个:

A natural transformation in our context will be a polymorphic function associated with two Haskell functor instances f and g with type signature (Functor f, Functor g) => forall a. f a -> g a. Which could be written with the following type synonym.

type Nat f g = forall a. f a -> g a

这对我“我会继续忽略这个”的态度来说是一记耳光。那么对于这个问题:为什么可以突然放弃仿函数约束?

最佳答案

Haskell 中不允许对类型同义词施加约束。即使对于数据类型,它在 Haskell 2010 中也已被弃用。相反,应该将约束放在对这种类型的值进行操作的函数上。

关于haskell - 自然变换中的仿函数在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21841985/

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