category-theory

Why Functor class has no return function?

半城伤御伤魂 提交于 2019-11-27 22:13:12
From categorical point of view, functor is pair of two maps (one between objects and another between arrows of categories), following some axioms. I have assumed, what every Functor instance is similar to mathematical definition i.e. can map both objects and functions, but Haskell's Functor class has only function fmap which maps functions. Why so? UPD In other words: Every Monad type M has an function return :: a -> M a . And Functor type F has no function return :: a -> F a , but only F x constructor. laughedelic First of all, there are two levels: types and values. As objects of Hask are

Are there contravariant monads?

情到浓时终转凉″ 提交于 2019-11-27 21:34:45
问题 Functors can be covariant and contravariant. Can this covariant/contravariant duality also be applied to monads? Something like: class Monad m where return :: a -> m a (>>=) :: m a -> (a -> m b) -> m b class ContraMonad m where return :: a -> m a contrabind :: m a -> (b -> m a) -> m b Does ContraMonad class make sense? Any examples? 回答1: Well, of course, it's possible to define it, but I doubt it would be of any use. There is a popular saying that "monad is just a monoid in a category of

To what extent are Applicative/Monad instances uniquely determined?

旧巷老猫 提交于 2019-11-27 19:17:12
问题 As described this question/answers, Functor instances are uniquely determined, if they exists. For lists, there are two well know Applicative instances: [] and ZipList. So Applicative isn't unique (see also Can GHC derive Functor and Applicative instances for a monad transformer? and Why is there no -XDeriveApplicative extension?). However, ZipList needs infinite lists, as its pure repeats a given element indefinitely. Are there other, perhaps better examples of data structures that have at

Monads as adjunctions

这一生的挚爱 提交于 2019-11-27 17:01:07
I've been reading about monads in category theory. One definition of monads uses a pair of adjoint functors. A monad is defined by a round-trip using those functors. Apparently adjunctions are very important in category theory, but I haven't seen any explanation of Haskell monads in terms of adjoint functors. Has anyone given it a thought? Edit : Just for fun, I'm going to do this right. Original answer preserved below The current adjunction code for category-extras now is in the adjunctions package: http://hackage.haskell.org/package/adjunctions I'm just going to work through the state monad

Is there a monad that doesn't have a corresponding monad transformer (except IO)?

冷暖自知 提交于 2019-11-27 11:25:07
So far, every monad (that can be represented as a data type) that I have encountered had a corresponding monad transformer, or could have one. Is there such a monad that can't have one? Or do all monads have a corresponding transformer? By a transformer t corresponding to monad m I mean that t Identity is isomorphic to m . And of course that it satisfies the monad transformer laws and that t n is a monad for any monad n . I'd like to see either a proof (ideally a constructive one) that every monad has one, or an example of a particular monad that doesn't have one (with a proof). I'm interested

Where do values fit in Category of Hask?

三世轮回 提交于 2019-11-27 10:11:24
问题 So we have Category of Hask, where: Types are the objects of the category Functions are the morphisms from object to object in the category. Similarly for Functor we have: a Type constructor as the mapping of objects from one category to another fmap for the mapping of morphisms from one category to another. Now, when we write program we basically transform values (not types) and it seems that the Category of Hask doesn't talk about values at all. I tried to fit values in the whole equation

What is Applicative Functor definition from the category theory POV?

不想你离开。 提交于 2019-11-27 10:09:17
问题 I was able to map Functor's definition from category theory to Haskell's definition in the following way: since objects of Hask are types, the functor F maps every type a of Hask to the new type F a by, roughly saying, prepending "F " to it. maps every morphism a -> b of Hask to the new morphism F a -> F b using fmap :: (a -> b) -> (f a -> f b) . So far, so good. Now I get to the Applicative , and can't find any mention of such a concept in textbooks. By looking at what it adds to Functor ,

What does “coalgebra” mean in the context of programming?

狂风中的少年 提交于 2019-11-27 08:54:29
问题 I have heard the term "coalgebras" several times in functional programming and PLT circles, especially when the discussion is about objects, comonads, lenses, and such. Googling this term gives pages that give mathematical description of these structures which is pretty much incomprehensible to me. Can anyone please explain what coalgebras mean in the context of programming, what is their significance, and how they relate to objects and comonads? 回答1: Algebras I think the place to start would

How much is applicative really about applying, rather than “combining”?

旧街凉风 提交于 2019-11-27 06:42:48
问题 For an uncertainty-propagating Approximate type, I'd like to have instances for Functor through Monad . This however doesn't work because I need a vector space structure on the contained types, so it must actually be restricted versions of the classes. As there still doesn't seem to be a standard library for those (or is there? please point me. There's rmonad, but it uses * rather than Constraint as the context kind, which seems just outdated to me), I wrote my own version for the time being.

Monads as adjunctions

南笙酒味 提交于 2019-11-26 18:49:25
问题 I've been reading about monads in category theory. One definition of monads uses a pair of adjoint functors. A monad is defined by a round-trip using those functors. Apparently adjunctions are very important in category theory, but I haven't seen any explanation of Haskell monads in terms of adjoint functors. Has anyone given it a thought? 回答1: Edit : Just for fun, I'm going to do this right. Original answer preserved below The current adjunction code for category-extras now is in the