category-theory

Categorical structure in Haskell

て烟熏妆下的殇ゞ 提交于 2019-12-05 02:21:33
Hask is usually thought to be the category whose objects are types and morphisms are functions. However, I've seen Conor McBride (@pigworker) warn against the use of Hask multiple times ( 1 , 2 , 3 ): I would discourage talk of "the Hask Category" because it subconsciously conditions you against looking for other categorical structure in Haskell programming. Note, I dislike the use of "Hask" as the name of the "category of Haskell types and functions": I fear that labelling one category as the Haskell category has the unfortunate side-effect of blinding us to the wealth of other categorical

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

ⅰ亾dé卋堺 提交于 2019-12-05 00:02:04
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 inverse of foo , at least not in Hask . I suppose s1 doesn't even have to have an inverse in Hask . Is

How to define equality for Category instances?

一笑奈何 提交于 2019-12-04 11:11:45
问题 In order to prove that for instance the Category laws hold for some operations on a data type, how do one decide how to define equality? Considering the following type for representing boolean expressions: data Exp = ETrue | EFalse | EAnd Exp Exp deriving (Eq) Is it feasible trying to prove that Exp forms a Category with identity ETrue and operator: (<&>) = EAnd without redefining the Eq instance? Using the default instance of Eq the left-identity law breaks, i.e: ETrue <&> e == e evaluates

Is Hask even a category?

末鹿安然 提交于 2019-12-04 06:55:23
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 different values, but the same morphism? In Haskell, we have this idea that every expression can be

Why is there a distinction between co and contravariant functors in Haskell but not Category Theory?

匆匆过客 提交于 2019-12-04 05:39:21
This answer from a Category Theory perspective includes the following statement: ...the truth is that there's no real distinction between co and contravariant functor, because every functor is just a covariant functor. ... More in details a contravariant functor F from a category C to a category D is nothing more than a (covariant) functor of type F : C op →D, from the opposite category of C to the category D. On the other hand, Haskell's Functor and Contravariant merely require fmap and contramap , respectively, to be defined for an instance. This suggests that, from the perspective of

Does each type have a unique catamorphism?

喜夏-厌秋 提交于 2019-12-04 03:09:21
Recently I've finally started to feel like I understand catamorphisms. I wrote some about them in a recent answer , but briefly I would say a catamorphism for a type abstracts over the process of recursively traversing a value of that type, with the pattern matches on that type reified into one function for each constructor the type has. While I would welcome any corrections on this point or on the longer version in the answer of mine linked above, I think I have this more or less down and that is not the subject of this question, just some background. Once I realized that the functions you

What is the analog of Category in programming

 ̄綄美尐妖づ 提交于 2019-12-04 02:16:12
问题 I found that there is an isomorphism between logic and programming, called Curry-Howard correspondence, so is there any such equivalence for Category theory, which helps to understand things like Functors or Monads? 回答1: Yes! It's called Curry–Howard–Lambek - it maps Category objects to types and morphisms to terms. So, typed lambda (function without name) or even function may be represented as cartesian-closed category, where Unite-type becomes a terminal object, set of types (or more

What would be the methods of a bi-comonad?

a 夏天 提交于 2019-12-04 01:26:57
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 extract ed ? Turns out neither the comonad nor bifunctors package contains something called Bicomonad . Question is, would such a class even make sense,

What are some types that discriminate between categories?

坚强是说给别人听的谎言 提交于 2019-12-03 16:51:49
问题 I'm still getting familiar with all this category theory stuff, and just about every example I see is with a Maybe or an Array. But I haven't found any examples that discriminate between these categories. For example, here are some of the questions I've still been unable to answer: whats a Semigroup that isn't also a Monoid? whats a Foldable that isn't also a Traversable? [Duplicate] whats an Functor that isn't also an Apply? whats an Apply that isn't also an Applicative? whats an Apply that

Do monad transformers, generally speaking, arise out of adjunctions?

一世执手 提交于 2019-12-03 15:46:14
问题 In Adjoint functors determine monad transformers, but where's lift?, Simon C has shown us the construction... newtype Three u f m a = Three { getThree :: u (m (f a)) } ... which, as the answers there discuss, can be given an instance Adjunction f u => MonadTrans (Three u f) ( adjunctions provides it as AdjointT). Any Hask/Hask adjunction thus leads to a monad transformer; in particular, StateT s arises in this manner from the currying adjunction between (,) s and (->) s . My follow-up