没有arr的箭头

Dan*_*ton 24 haskell arrows category-theory

如果我们将对类别的理解限制Category为Haskell中的常用类:

class Category c where
  id :: c x x
  (>>>) :: c x y -> c y z -> c x z
Run Code Online (Sandbox Code Playgroud)

那么让我们说a ArrowCategory另外一个:

class Category c => Arrow c where
  (***) :: c x y -> c x' y' -> c (x,x') (y,y')
  (&&&) :: c x y -> c x y' -> c x (y,y')
Run Code Online (Sandbox Code Playgroud)

我们可以很容易地推导出:

first :: c x y -> c (x,z) (y,z)
first a = a *** id

second :: c x y -> c (z,x) (z,y)
second a = id *** a
Run Code Online (Sandbox Code Playgroud)

或者,我们可以得出(***)firstsecond:

a1 *** a2 = first a1 >>> second a2
Run Code Online (Sandbox Code Playgroud)

我们还可以推导出:

dup :: c x (x,x)
dup = id &&& id
Run Code Online (Sandbox Code Playgroud)

或者我们可以得出(&&&)给定的dup(***):

a1 &&& a2 = dup >>> (a1 *** a2)
Run Code Online (Sandbox Code Playgroud)

我的意思是什么,我的问题是什么?就是这样:

什么是Arrowarr?它看起来非常连贯和有用.是否有任何箭头法律(除了类别法律之外)不涉及arr并保持原样在这里?这在类别理论中意味着什么呢?


我基本上从reddit中窃取了这个问题,但是对其进行了概括和阐述:http: //www.reddit.com/r/haskell/comments/2e0ane/category_with_fanout_and_split_but_not_an_arrow/

谷口昂*_*口昂平 2

正如Arrow有产品的类别一样,Arrow没有arr产品的类别也是如此(因此类别定律始终成立)。

arr是一个从 Hask 类别到c类别的函子。下面显示的代码表明了这一点。arr提供了一种将普通函数(Hask 中的态射)提升到实例化c类别的方法。这有点像fmap(endofunctor from Hask to Hask),但更通用。与此相关,这里的一些箭头定律描述了函子定律(尽管也有乘积定律)。

因此,通过省略arr,您将失去提升正常功能的功能,或者从另一个角度来看,无需实现它。然而,所有其他特征都是相同的。

{-# LANGUAGE TypeOperators, RankNTypes #-}

-- | Functor arrow
type (:->) c d = forall a b. c a b -> d a b

-- | Hask category; types are objects, functions are morphisms.
type Hask = (->)

arr :: Arrow c => Hask :-> c
arr = Control.Arrow.arr
Run Code Online (Sandbox Code Playgroud)