category-theory

How are functors in Haskell related to functors in category theory?

一个人想着一个人 提交于 2019-12-03 04:53:39
问题 For as far as I understand, a functor is a mapping between two categories, for example from objects in to objects in where and are categories. In Haskell there is Hask in which the objects are Haskell types and the morphisms are Haskell functions. However, the Functor type class has a function fmap which maps between these types (which are thus objects and not categories themselves): fmap :: (a -> b) -> f a -> f b f a and f b are both objects in Hask . Does this mean every instance of Functor

Can liftM differ from liftA?

江枫思渺然 提交于 2019-12-03 04:46:23
问题 According to the Typeclassopedia (among other sources), Applicative logically belongs between Monad and Pointed (and thus Functor ) in the type class hierarchy, so we would ideally have something like this if the Haskell prelude were written today: class Functor f where fmap :: (a -> b) -> f a -> f b class Functor f => Pointed f where pure :: a -> f a class Pointed f => Applicative f where (<*>) :: f (a -> b) -> f a -> f b class Applicative m => Monad m where -- either the traditional bind

What is monoid homomorphism exactly?

匆匆过客 提交于 2019-12-03 04:04:09
问题 I've read about monoid homomorphism from Monoid Morphisms, Products, and Coproducts and could not understand 100%. The author says (emphasis original): The length function maps from String to Int while preserving the monoid structure . Such a function, that maps from one monoid to another in such a preserving way, is called a monoid homomorphism . In general, for monoids M and N , a homomorphism f: M => N , and all values x:M , y:M , the following equations hold: f(x |+| y) == (f(x) |+| f(y))

What are zygo/meta/histo/para/futu/dyna/whatever-morphisms?

别等时光非礼了梦想. 提交于 2019-12-03 03:09:59
问题 Is there a list of them with examples accessible to a person without extensive category theory knowledge? 回答1: Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire(PDF) should help as well. The notation will get a bit hairy, but reading it a few times you should be able to knock down that list of yours. Also, take a look at the recursion schemes (archived) blog post, the blogger plans on presenting each individually soon, so check back to it regularly --I guess. 回答2: Edward

What is a monad in FP, in categorical terms?

不羁的心 提交于 2019-12-03 01:29:07
问题 Every time someone promises to "explain monads", my interest is piqued, only to be replaced by frustration when the alleged "explanation" is a long list of examples terminated by some off-hand remark that the "mathematical theory" behind the "esoteric ideas" is "too complicated to explain at this point". Now I'm asking for the opposite. I have a solid grasp on category theory and I'm not afraid of diagram chasing, Yoneda's lemma or derived functors (and indeed on monads and adjunctions in the

Relation between `DList` and `[]` with Codensity

早过忘川 提交于 2019-12-03 01:28:35
I've been experimenting with Codensity lately which is supposed to relate DList with [] among other things. Anyway, I've never found code that states this relation. After some experiments I ended up with this: {-# LANGUAGE RankNTypes #-} module Codensity where newtype Codensity f a = Codensity { runCodensity :: forall b. (a -> f b) -> f b } type DList a = Codensity [] [a] nil :: DList a nil = Codensity ($ []) infixr 5 `cons` cons :: a -> DList a -> DList a cons x (Codensity xs) = Codensity ($ (xs (x:))) append :: DList a -> DList a -> DList a append (Codensity xs) ys = Codensity ($ (xs (++

Open Type Level Proofs in Haskell/Idris

僤鯓⒐⒋嵵緔 提交于 2019-12-02 20:45:15
In Idris/Haskell, one can prove properties of data by annotating the types and using GADT constructors, such as with Vect, however, this requires hardcoding the property into the type (e.g. a Vect has to be a separate type from a List). Is it possible to have types with an open set of properties (such as list carrying both a length and running average), for example by overloading constructors or using something in the vein of Effect? I believe that McBride has answered that question (for Type Theory) in his ornament paper (pdf) . The concept you are looking for is the one of an algebraic

How are functors in Haskell related to functors in category theory?

蹲街弑〆低调 提交于 2019-12-02 18:12:18
For as far as I understand, a functor is a mapping between two categories, for example from objects in to objects in where and are categories. In Haskell there is Hask in which the objects are Haskell types and the morphisms are Haskell functions. However, the Functor type class has a function fmap which maps between these types (which are thus objects and not categories themselves): fmap :: (a -> b) -> f a -> f b f a and f b are both objects in Hask . Does this mean every instance of Functor in Haskell is an endofunctor, and if not does Functor really represent a functor? What am I missing

Can liftM differ from liftA?

隐身守侯 提交于 2019-12-02 17:59:41
According to the Typeclassopedia (among other sources), Applicative logically belongs between Monad and Pointed (and thus Functor ) in the type class hierarchy, so we would ideally have something like this if the Haskell prelude were written today: class Functor f where fmap :: (a -> b) -> f a -> f b class Functor f => Pointed f where pure :: a -> f a class Pointed f => Applicative f where (<*>) :: f (a -> b) -> f a -> f b class Applicative m => Monad m where -- either the traditional bind operation (>>=) :: (m a) -> (a -> m b) -> m b -- or the join operation, which together with fmap is

What is a monad in FP, in categorical terms?

帅比萌擦擦* 提交于 2019-12-02 16:42:43
Every time someone promises to "explain monads", my interest is piqued, only to be replaced by frustration when the alleged "explanation" is a long list of examples terminated by some off-hand remark that the "mathematical theory" behind the "esoteric ideas" is "too complicated to explain at this point". Now I'm asking for the opposite. I have a solid grasp on category theory and I'm not afraid of diagram chasing, Yoneda's lemma or derived functors (and indeed on monads and adjunctions in the categorical sense). Could someone give me a clear and concise definition of what a monad is in