category-theory

What kind of morphism is `filter` in category theory?

穿精又带淫゛_ 提交于 2019-12-10 01:53:02
问题 In category theory, is the filter operation considered a morphism? If yes, what kind of morphism is it? Example (in Scala) val myNums: Seq[Int] = Seq(-1, 3, -4, 2) myNums.filter(_ > 0) // Seq[Int] = List(3, 2) // result = subset, same type myNums.filter(_ > -99) // Seq[Int] = List(-1, 3, -4, 2) // result = identical than original myNums.filter(_ > 99) // Seq[Int] = List() // result = empty, same type 回答1: To answer are question like this, I'd like to first understand what is the essence of

Do the monadic liftM and the functorial fmap have to be equivalent?

丶灬走出姿态 提交于 2019-12-09 11:13:22
问题 (Note: I'm phrasing the question using Haskell terminology; answers are welcome to use the same terminology and/or the mathematical language of category theory, including proper mathematical definitions and axioms where I speak of functor and monad laws.) It is well known that every monad is also a functor, with the functor's fmap equivalent to the monad's liftM . This makes sense, and of course holds for all common/reasonable monad instances. My question is whether this equivalence of fmap

Use cases for adjunctions in Haskell

匆匆过客 提交于 2019-12-09 05:21:53
问题 I have been reading up on adjunctions during the last couple of days. While I start to understand their importance from a theoretical point of view, I wonder how and why people use them in Haskell. Data.Functor.Adjunction provides an implementation and among its instances are free functor / forgetful functor and curry / uncurry. Again those are very interesting from the theoretical view point but I can't see how I would use them for more practical programming problems. Are there examples of

Generalized `fold` or how to perform `fold` and `map` at a time

雨燕双飞 提交于 2019-12-07 06:13:33
问题 (Apology by the title, I can't do better) My question is to find some generalized struct or "standard" function to perform the next thing: xmap :: (a -> b) -> f a -> g b then, we can map not only elements, by also the entire struct. Some (not real) example xmap id myBinaryTree :: [a] at the moment, I must to do a explicit structure conversor (typical fromList , toList ) then toList . fmap id -- if source struct has map fmap id . fromList -- if destination struct has map (to perform toStruct ,

What is this thing similar to KleisliFunctor?

一个人想着一个人 提交于 2019-12-07 03:22:33
问题 Here is how we can define KleisliFunctor: class (Monad m, Functor f) => KleisliFunctor m f where kmap :: (a -> m b) -> f a -> f b kmap f = kjoin . fmap f kjoin :: f (m a) -> f a kjoin = kmap id Does this type class class (Functor f, Monad m) => Absorb f m where (>>~) :: f a -> (a -> m b) -> m b a >>~ f = ajoin $ fmap f a ajoin :: f (m a) -> m a ajoin a = a >>~ id fit somewhere into category theory? What are the laws? Are they a >>~ g . f === fmap f a >>~ g a >>~ (f >=> g) === a >>~ f >>= g ?

Where does the name “section” come from for a partially applied infix operator?

纵然是瞬间 提交于 2019-12-06 18:30:01
问题 In Haskell, we use the term "section" to indicate a partially applied function used in infix position. For instance, for a function foo :: a -> b -> c and values x :: a and y :: b , we have the two sections s1 = (x `foo`) :: b -> c == \b -> foo x b and s2 = (`foo` y) :: a -> c == \a -> foo a y In category theory, however, a section g of f is defined as a right inverse of f (so that f . g == id ). I don't see an obvious connection between the two definitions. For instance, s1 is clearly not an

Is Hask even a category?

て烟熏妆下的殇ゞ 提交于 2019-12-06 02:49:58
问题 https://wiki.haskell.org/Hask: Consider: undef1 = undefined :: a -> b undef2 = \_ -> undefined Note that these are not the same value: seq undef1 () = undefined seq undef2 () = () This might be a problem, because undef1 . id = undef2 . In order to make Hask a category, we define two functions f and g as the same morphism if f x = g x for all x . Thus undef1 and undef2 are different values , but the same morphism in Hask . What does it mean or how can I check, that: undef1 and undef2 are

What would be the methods of a bi-comonad?

不羁的心 提交于 2019-12-05 16:08:56
问题 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 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 ? Turns out neither the comonad nor bifunctors

Typeclass for (what seems to be) a contravariant functor implementing function inversion

你说的曾经没有我的故事 提交于 2019-12-05 05:58:24
Lets say I have the following import Control.Category (Category, (.), id) data Invertible a b = Invertible (a -> b) (b -> a) instance Category Invertible where id = Invertible Prelude.id Prelude.id (Invertible f f') . (Invertible g g') = Invertible (f Prelude.. g) (g' Prelude.. f') invert (Invertible x y) = Invertible y x Note that the following is true: invert (g . f) == invert f . invert g This structure seems very similar to a contravariant functor (wikipedia) , as it follows the same axiom: F(g . f) = F(f) . F(g) In my case, F is simply invert . I looked at Data.Functor.Contravariant

What kind of morphism is `filter` in category theory?

核能气质少年 提交于 2019-12-05 02:41:10
In category theory, is the filter operation considered a morphism? If yes, what kind of morphism is it? Example (in Scala) val myNums: Seq[Int] = Seq(-1, 3, -4, 2) myNums.filter(_ > 0) // Seq[Int] = List(3, 2) // result = subset, same type myNums.filter(_ > -99) // Seq[Int] = List(-1, 3, -4, 2) // result = identical than original myNums.filter(_ > 99) // Seq[Int] = List() // result = empty, same type To answer are question like this, I'd like to first understand what is the essence of filtering. For instance, does it matter that the input is a list? Could you filter a tree? I don't see why not