双连接器的方法是什么? [英] What would be the methods of a bi-comonad?

查看:165
本文介绍了双连接器的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在讨论更多有用的标准课程以向其中的推荐

While musing what more useful standard class to suggest to this one

class Coordinate c where
  createCoordinate :: x -> y -> c x y
  getFirst :: c x y -> x
  getSecond :: c x y -> y
  addCoordinates :: (Num x, Num y) => c x y -> c x y -> c x y

它发生在我身上,而不是某个 VectorSpace -y R2 ,一个更普遍的野兽可能会潜伏在这里:a Type - >类型 - >键入,其中两个包含的类型都可以被提取。嗯,也许他们可以 extract ed ?

it occured me that instead of something VectorSpace-y or R2, a rather more general beast might lurk here: a Type -> Type -> Type whose two contained types can both be extracted. Hm, perhaps they can be extracted?

原来 comonad 或 bifunctors 软件包包含一些名为 Bicomonad 的东西。问题是,从类别理论上讲,这样的班级是否有意义?不同于 Bimonad (它也没有定义,我也看不清楚),一个天真的定义似乎是合理的:

Turns out neither the comonad nor bifunctors package contains something called Bicomonad. Question is, would such a class even make sense, category-theoretically? Unlike Bimonad (which also isn't defined, and I couldn't really see how might look), a naïve definition seems plausible:

class Bifunctor c => Bicomonad c where
  fst :: c x y -> x
  snd :: c x y -> y
  bidup :: c x y -> c (c x y) (c x y)

可能与法律有关

probably with the laws

fst . bidup ≡ id
snd . bidup ≡ id
bimap fst snd . bidup ≡ id
bimap bidup bidup . bidup ≡ bidup . bidup

但是我发现它令人不安, bidup 包含相同的类型,并且还有很多其他的,也许是更好的可以想象的签名。

but I find it disquieting that both fields of the result of bidup contain the same type, and there are quite a number of other, perhaps "better" conceivable signatures.

有什么想法?

推荐答案

这不是答案,但对于 Bimonad ,这个怎么样?

This is not an answer, but for Bimonad, how about this?

class Biapplicative p => Bimonad p where
  (>>==) :: p a b -> (a -> b -> p c d) -> p c d

biap :: Bimonad p => p (a -> b) (c -> d) -> p a c -> p b d
biap p q = p >>== \ab cd -> q >>== \a c -> bipure (ab a) (cd c)

instance Bimonad (,) where
  (a,b) >>== f = f a b

我不知道这是绝对正确还是有趣,甚至是远程有用,但它从Haskell的角度来看是正确的。它是否与您的 Bicomonad 或类似的东西相匹配?

I don't know if this is categorically right/interesting, or even remotely useful, but it smells right from a Haskell perspective. Does it match your Bicomonad or something similar?

这篇关于双连接器的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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