Many types of optics have a van Laarhoven representation.
For example, a Lens
of type Lens s t a b
can be represented as:
Functor f => (a -> f b) -> s -> f t
Run Code Online (Sandbox Code Playgroud)
Similarly a Traversal
, can be represented in a similar way, swapping the Functor
constraint for Applicative
:
Applicative f => (a -> f b) -> s -> f t
Run Code Online (Sandbox Code Playgroud)
几种光学框架(例如Monocle和Arrow)定义了一种类型Optional
。
在《单片眼镜光学》中,层次结构 Optional
介于Lens
和之间Traversal
根据我的理解:如果 …
爱德华·克梅特(Edward Kmett)的光学图书馆;Control.Lens定义了大量类型。
其中大多数具有相对自我解释的名称,例如Traversal和Fold。
它还定义了一些名称不那么明显的类型,例如Bazaar
在“义卖市场”页面上:
aka索引的笛卡尔商店comonad,索引的Kleene商店comonad或索引的FunList。
...
通常,集市上有很多商店,您可以轻松添加更多。
我无法弄清楚Market类型名称背后的原因。我认为这在某种程度上也与商店monads / comonads有关?它是否正确?
我刚刚开始学习Haskell,并且对范围的行为感到惊讶.
我知道这[1, 2 .. 10]
是语法糖enumFromThenTo 1 2 10
.
从其他编程语言(比如Python)的我已经习惯了被范围内使用指定第一,最后和步参数,这样Haskell的则是相当于第一+步 Python编写的.
为什么使用的Haskell 然后,而不是步骤,以限定在序列中的值之间的间隔?
克里斯·彭纳 (Chris Penner) 的这篇文章谈到了“枯萎的光学”;可用于从结构中过滤项目的光学元件。
本文对这些光学器件使用以下“Van Laarhoven”表示:
type Wither s t a b = forall f. Alternative f => (a -> f b) -> s -> f t
Run Code Online (Sandbox Code Playgroud)
大多数(如果不是全部)Van Laarhoven 光学具有等效的 profunctor 表示。例如镜头:
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
Run Code Online (Sandbox Code Playgroud)
相当于:
type Lens s t a b = forall p. Strong p => p a b -> p s t
Run Code Online (Sandbox Code Playgroud)
是否Wither
也有 Profuctor 代表?如果是这样,那是什么?
newtype Comparison a
定义于Data.Functor.Contravariant
.
在定义的此模块的版本中contravariant-1.5
,Monoid
实例on Contravariant
定义如下:
instance Monoid (Comparison a) where
mempty = Comparison (\_ _ -> EQ)
mappend (Comparison p) (Comparison q) = Comparison $ mappend p q
Run Code Online (Sandbox Code Playgroud)
Data.Functor.Contravariant
也用基数定义(显然是GHC 8.6.1).在base中,Monoid
实例on Comparison
定义如下:
deriving instance Semigroup (Comparison a)
deriving instance Monoid (Comparison a)
Run Code Online (Sandbox Code Playgroud)
什么使实例Monoid (Comparison a)
能够在base中自动派生?
我应该在哪里查看mempty
和mappend
它的定义?
haskell ×5
lenses ×3
haskell-lens ×1
monoids ×1
profunctor ×1
python ×1
range ×1
scala ×1
terminology ×1