category-theory

Is this property of a functor stronger than a monad?

一个人想着一个人 提交于 2019-12-17 15:34:33
问题 While thinking about how to generalize monads, I came up with the following property of a functor F: inject :: (a -> F b) -> F(a -> b) -- which should be a natural transformation in both a and b. In absence of a better name, I call the functor F bindable if there exists a natural transformation inject shown above. The main question is, whether this property is already known and has a name, and how is it related to other well-known properties of functors (such as, being applicative, monadic,

What would be a good example of an endofunctor that is not the identity functor?

大憨熊 提交于 2019-12-14 02:25:03
问题 In Professor Frisby Introduces Composable Functional JavaScript the identity functor was introduced: const Box = x => ({ map: f => Box(f(x)), fold: f => f(x) // for testing }) I spent the better part of the day understanding functors and why the above JavaScript code is actually the identity functor. So I thought I would alter it to get a "real" functor that is not the identity functor. I came up with this: const Endo = x => ({ map: f => Endo(f(x).split('')), fold: f => f(x).split('') // for

Monads not with “flatMap” but “flatUnit”? [closed]

左心房为你撑大大i 提交于 2019-12-13 11:32:00
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year . Monads in category theory is defined by triples T, unit, flat ⟩. class Monad t where map :: (a -> b) -> (t a -> t b) -- functorial action unit :: a -> t a flat :: t (t a) -> t a class KleisliTriple t where unit :: a -> t a flatMap :: t a -> (a -> t b) -> t b KleisliTriple flats the structure by the

Does each type have a unique catamorphism?

喜你入骨 提交于 2019-12-12 08:25:25
问题 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

Why is a -> a not a functor?

一笑奈何 提交于 2019-12-11 06:43:42
问题 Specifically referring to https://bartoszmilewski.com/2015/04/07/natural-transformations/ Author says "This is not a functor". I can define fmap :: (a -> b) -> (a -> a) -> (b -> b) as fmap f aa = id , which seems to adhere to the functor laws. I don't mean why it's not explicitly part of the Functor typeclass in X language, I just mean why it wouldn't be acknowledged as a functor. 回答1: In the context of Haskell, I think you're talking about newtype Endo a = Endo (a -> a) (using a newtype to

Matrix as Applicative functor, which is not Monad

允我心安 提交于 2019-12-11 02:36:09
问题 I run into examples of Applicatives that are not Monads. I like the multi-dimensional array example but I did not get it completely. Let's take a matrix M[A] . Could you show that M[A] is an Applicative but not a Monad with Scala code ? Do you have any "real-world" examples of using matrices as Applicatives ? 回答1: Something like M[T] <*> M[T => U] is applicative: val A = [[1,2],[1,2]] //let's assume such imaginary syntax for arrays val B = [[*2, *3], [*5, *2]] A <*> B === [[2,6],[5,4]] There

Why does Haskell have non-strict functions (semantics)? [closed]

谁说胖子不能爱 提交于 2019-12-10 14:21:40
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . According to this article on denotational semantics in haskell All types have bottom, and a function f:A->B is strict if it maps the

Do the functor laws prove complete preservation of structure?

不打扰是莪最后的温柔 提交于 2019-12-10 12:52:13
问题 In the documenation for Data.Functor the following two are stated as the functor laws, which all functors should adhere to. fmap id == id fmap (f . g) == fmap f . fmap g The way my intuition tells me functors should work is that they should be "structure preserving", or in other words, if you have a function f :: a -> b and it's inverse g :: b -> a then fmap f . fmap g == id I have not been able to come up with an implementation of fmap that would adhere to the first two laws and violate the

Functor instance for generic polymorphic ADTs in Haskell?

烈酒焚心 提交于 2019-12-10 12:38:42
问题 When it comes to applying category theory for generic programming Haskell does a very good job, for instance with libraries like recursion-schemes . However one thing I'm not sure of is how to create a generic functor instance for polymorphic types. If you have a polymorphic type, like a List or a Tree, you can create a functor from (Hask × Hask) to Hask that represents them. For example: data ListF a b = NilF | ConsF a b -- L(A,B) = 1+A×B data TreeF a b = EmptyF | NodeF a b b -- T(A,B) = 1+A

Categorical structure in Haskell

血红的双手。 提交于 2019-12-10 03:22:52
问题 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