scala,types,monads,category-theory

I would say that less bugs are expected because you give the complier as much information as possible and therefore it can find issues already during compilation. Otherwise they would occur at runtime. Regarding less code I am not sure, but maybe the idea is that Scalaz does a lot...

The notion of exponential can be defined in general terms, beyond Hask/Set. A category with exponentials and products is called a cartesian closed category. This is a key notion in theoretical computer science since each c.c. category is essentially a model of the typed lambda calculus. Roughly, in a cartesian...

I found one possible valid way. Let our data type data Person = Person { name :: String , age :: Int } deriving (Show, Eq, Ord) to grant overload selectively (and interdependently) instances we only need class CPerson p where get :: p -> Person -- grant access to...

haskell,monads,category-theory

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 endofunctors". What it means is, first of all, that we have a category of endofunctors (meaning, (covariant) functors...

id is supposed to be the identity morphism for any given Haskell type. The identify morphism for a type A in Hask is a function of type A -> A, but it's not just any function of type A -> A; it has to obey the category laws. In particular,...

A terminal object in a category by definition is an object T with the property that for any object C in the category, there is exactly one arrow C -> T. In the category of sets, a singleton object, for example {1} has this property: For any set S there...

haskell,function-composition,arrows,category-theory

As Hackage and/or Hoogle will tell you, (>>>) :: Category k => a`k`b -> b`k`c -> a`k`c (<<<) :: Category k => b`k`c -> a`k`b -> a`k`c Observe that the latter is actually the same as (.) :: Category k => b`k`c -> a`k`b -> a`k`c or, in its Prelude...

This seems like not a bad pass at a translation of the raw structure. But you cannot leverage the type system to do any of the checking for you. The data-category package (https://hackage.haskell.org/package/data-category) uses a neat trick to do your construction "one level up" and enforce some properties of composition...

haskell,category-theory,abstract-algebra

Do notation is just syntactic sugar for >>=. Code such as do x <- a b -- b is an expression possibly involving x is desugared to a >>= \x -> b If you are studying monads in CT, you will probably find that they are being defined as functors...

haskell,proof,category-theory,correctness,idris

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 ornament (emphasis mine): An algebra φ describes a structural method to interpret data, giving rise to a fold φ oper- ation, applying...

haskell,functional-programming,functor,category-theory

An indexed functor is, to use spacesuitburritoesque wording, "a container that also contains a mapping". I.e. a value f j k a will "contain" some sort of morphism(s) j -> k (not necessarily functions, can be more general arrows) and also values of type a. For those values, the container...

haskell,functor,category-theory,comonad

So, assuming f and g are proper functors, forall a. f a -> g a is a natural transformation. We could make it a bit prettier: type f ~> g = forall a. f a -> g a Natural transformations like this let us form a category of Haskell Functors,...

haskell,recursion,functor,category-theory

TBH I'm not sure how helpful this solution is to you because it still requires an extra newtype wrapping for these fixed-point functors, but here we go: You can keep using your generic cata if you do some wrapping/unwrapping Given the following two helper functions: unwrapFixBifunctor :: (Bifunctor f) =>...

lambda,functional-programming,category-theory,type-theory

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 complex structure) is product, and apply+currying is exponential.

Here is a rather principled solution to implementing head and tail in one go (full gist): First of all, we know how to append lists (it will be useful later on): append :: List a -> List a -> List a append (Abstr xs) (Abstr ys) = Abstr (\ f...

haskell,functor,applicative,category-theory

The "neat alternative presentation" for Applicative is based on the following two equivalencies pure a = fmap (const a) unit unit = pure () ff <*> fa = fmap (\(f,a) -> f a) $ ff ** fa fa ** fb = pure (,) <*> fa <*> fb The trick to...

/** Higher order functor */ trait HFunctor[F[_]] { def ffmap[G[_]: Functor, A, B](f: A => B): F[G[A]] => F[G[B]] def hfmap[G[_], H[_]](t: G ~> H): ({type λ[α] = F[G[α]]})#λ ~> ({type λ[α] = F[H[α]]})#λ } trait Functor[F[_]] { self => def fmap[A, B](f: A => B): F[A] => F[B] //...