(< *>)中的*是否具有特殊含义? [英] Does * in (<*>) have a special meaning?

查看:100
本文介绍了(< *>)中的*是否具有特殊含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图加深我对Haskell中符号的理解:

Trying to expand my understanding about symbols in Haskell :

  • ($):函数应用程序运算符(允许您在函数上应用参数)
  • (&):功能应用程序运算符的翻转版本? (&) = flip ($)
  • (<>):关联运算符(您可以在半群和Monoid中找到它)
  • (<$>):函数应用程序($)放在Functor结构上
  • (<&>):翻转的函子图
  • ($) : Function Application operator (Allow you to apply arguments over a function)
  • (&) : flipped version of Function Application Operator? (&) = flip ($)
  • (<>) : associative operator (You'll find it in Semigroups and Monoids)
  • (<$>) : function application ($) lifted over a Functor structure
  • (<&>) : flipped functor map

我们可以在(*)(<*>)之间建立链接吗?

Can we make a link between (*) and (<*>)?

我实际上不理解*的含义...

I don't understand the meaning of * actually...

推荐答案

这是故意的. <*>具有张量积的特征.最好在列表monad中看到:

This is deliberate. <*> has characteristics of a tensor product. This is best seen in the list monad:

Prelude> (,) <$> ['a'..'e'] <*> [0..4]
[('a',0),('a',1),('a',2),('a',3),('a',4)
,('b',0),('b',1),('b',2),('b',3),('b',4)
,('c',0),('c',1),('c',2),('c',3),('c',4)
,('d',0),('d',1),('d',2),('d',3),('d',4)
,('e',0),('e',1),('e',2),('e',3),('e',4)]

通常,应用函子(又名单形函子)是根据两个对象(即产品类型,aka元组或通过在仿函数后面的两个函数自变量)到仿函数之前的产品的仿函数结果.因此,这确实是一个相当不错的产品操作.

More generally, applicative functors (aka monoidal functors) map from the product of two objects (i.e. product type, aka tuple or via currying two function arguments) behind the functor to the functor-result of a product before the functor. So it's a pretty product-ey operation indeed.

φ A B : FA FB F ( A B )

φA,B: F AF BF(AB)

...在Haskell中,

...in Haskell,

φ :: (f a, f b) -> f (a,b)
φ = uncurry (liftA2 (,))
-- recall `liftA2 f x y = f <$> x <*> y`

甚至

{-# LANGUAGE TypeOperators #-}
type x ⊗ y = (x,y)

φ :: f a ⊗ f b -> f (a⊗b)

要了解历史,请查看 McBride and Paterson 2008 (doi: 10.1017/S0956796807006326 ),它首先介绍了Applicative类型类.他们注意到

To see the historical side, look into McBride and Paterson 2008 (doi:10.1017/S0956796807006326), the paper that first introduced the Applicative typeclass. They note

Applicative类具有非对称操作,但是有一个等效的对称定义.

The Applicative class features the asymmetrical operation , but there is an equivalent symmetrical definition.

class Functor f -> Monoidal f where
    unit :: f ()
    (★) :: f a -> f b -> f (a,b)

对于任何应用函子,这些操作显然是可定义的...

These operations are clearly definable for any Applicative functor...

因此,<*>是McBride和Paterson的运算符的ASCII格式,反过来又是的应用化"形式,类别理论家将其称为非咖喱形式φ.

So, the <*> is an ASCII rendition of McBride and Paterson's operator, which in turn is an "applicativised" form of which the category theorists call, in uncurried form, φ.

这篇关于(&lt; *&gt;)中的*是否具有特殊含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆