category-theory

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

蓝咒 提交于 2019-12-02 16:39:02
Is there a list of them with examples accessible to a person without extensive category theory knowledge? 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. Edward Kmett recently posted a Field Guide to recursion schemes , perhaps it helps? Start with learning about

What should a “higher order Traversable” class look like?

大憨熊 提交于 2019-12-01 17:46:38
问题 In this answer I made up on the spot something which looks a bit like a "higher order Traversable ": like Traversable but for functors from the category of endofunctors on Hask to Hask. {-# LANGUAGE RankNTypes #-} import Data.Functor.Compose import Data.Functor.Identity class HFunctor t where hmap :: (forall x. f x -> g x) -> t f -> t g class HFunctor t => HTraversable t where htraverse :: Applicative g => (forall x. f x -> g x) -> t f -> g (t Identity) htraverse eta = hsequence . hmap eta

Lax monoidal functors with a different monoidal structure

感情迁移 提交于 2019-11-30 11:20:01
问题 Applicative functors are well-known and well-loved among Haskellers, for their ability to apply functions in an effectful context. In category-theoretic terms, it can be shown that the methods of Applicative : pure :: a -> f a (<*>) :: f (a -> b) -> f a -> f b are equivalent to having a Functor f with the operations: unit :: f () (**) :: (f a, f b) -> f (a,b) the idea being that to write pure you just replace the () in unit with the given value, and to write (<*>) you squish the function and

What's the relation of fold on Option, Either etc and fold on Traversable?

对着背影说爱祢 提交于 2019-11-30 08:57:48
Scalaz provides a method named fold for various ADTs such as Boolean , Option[_] , Validation[_, _] , Either[_, _] etc. This method basically takes functions corresponding to all possible cases for that given ADT. In other words, a pattern match shown below: x match { case Case1(a, b, c) => f(a, b, c) case Case2(a, b) => g(a, b) . . case CaseN => z } is equivalent to: x.fold(f, g, ..., z) Some examples: scala> (9 == 8).fold("foo", "bar") res0: java.lang.String = bar scala> 5.some.fold(2 *, 2) res1: Int = 10 scala> 5.left[String].fold(2 +, "[" +) res2: Any = 7 scala> 5.fail[String].fold(2 +, "[

Once I have an F-Algebra, can I define Foldable and Traversable in terms of it?

若如初见. 提交于 2019-11-30 08:48:32
I have defined an F-Algebra , as per Bartosz Milewski's articles ( one , two ): (This is not to say my code is an exact embodiment of Bartosz's ideas, it's merely my limited understanding of them, and any faults are mine alone.) module Algebra where data Expr a = Branch [a] | Leaf Int instance Functor Expr where fmap f (Branch xs) = Branch (fmap f xs) fmap _ (Leaf i ) = Leaf i newtype Fix a = Fix { unFix :: a (Fix a) } branch = Fix . Branch leaf = Fix . Leaf -- | This is an example algebra. evalSum (Branch xs) = sum xs evalSum (Leaf i ) = i cata f = f . fmap (cata f) . unFix I can now do

Why is `pure` only required for Applicative and not already for Functor? [duplicate]

冷暖自知 提交于 2019-11-30 05:19:27
This question already has an answer here: Why Functor class has no return function? 4 answers Reading this Wikibook about Haskell and Category Theory basics , I learn about Functors: A functor is essentially a transformation between categories, so given categories C and D, a functor F : C -> D maps any object A in C to F(A), in D. maps morphisms f : A -> B in C to F(f) : F(A) -> F(B) in D. ... which sounds all nice. Later an example is provided: Let's have a sample instance, too: instance Functor Maybe where fmap f (Just x) = Just (f x) fmap _ Nothing = Nothing Here's the key part: the type

What's the relationship between profunctors and arrows?

倾然丶 夕夏残阳落幕 提交于 2019-11-30 03:44:39
Apparently, every Arrow is a Strong profunctor. Indeed ^>> and >>^ correspond to lmap and rmap . And first' and second' are just the same as first and second . Similarly every ArrowChoice is also Choice . What profunctors lack compared to arrows is the ability to compose them. If we add composition, will we get an arrow? In other words, if a (strong) profunctor is also a category , is it already an arrow? If not, what's missing? What profunctors lack compared to arrows is the ability to compose them. If we add composition, will we get an arrow? MONOIDS This is exactly the question tackled in

What is exactly an indexed functor in Haskell and what are its usages?

流过昼夜 提交于 2019-11-30 00:49:41
问题 When studying functors in Haskell I came up with Functor.Indexed type of functor. This functor defines an operation called imap . I didn't understood its definition and imap signature: imap :: (a -> b) -> f j k a -> f j k b . I tried to find it s formal definition and found only this: http://ncatlab.org/nlab/show/indexed+functor . But it really didn't help me at all. So can someone clarify in more simple words this kind of functor and in what cases should I use it? Thanks. 回答1: An indexed

Foldable, Monoid and Monad

心不动则不痛 提交于 2019-11-29 23:01:03
Consider the following signature of foldMap foldMap :: (Foldable t, Monoid m) => (a -> m) -> t a -> m This is very similar to "bind", just with the arguments swapped: (>>=) :: Monad m => m a -> (a -> m b) -> m b It seems to me that there therefore must be some sort of relationship between Foldable , Monoid and Monad , but I can't find it in the superclasses. Presumably I can transform one or two of these into the other but I'm not sure how. Could that relationship be detailed? ThreeFx Monoid and Monad Wow, this is actually one of the rare times we can use the quote: A monad is just a monoid in

Can a monad be a comonad?

折月煮酒 提交于 2019-11-29 21:31:27
I know what a monad is. I think I have correctly wrapped my mind around what a comonad is. (Or rather, what one is seems simple enough; the tricky part is comprehending what's useful about this...) My question is: Can something be a monad and a comonad? I foresee two possible answers: Yes, this is common and widely useful. No, they do such different jobs that there would be no reason to want something to be both. So, which is it? Philip JF Yes. Turning some comments into an answer: newtype Identity a = Identity {runIdenity :: a} deriving Functor instance Monad Identity where return = Identity