This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Edward Kmett Discrimination is Wrong: Improving Productivity | |
* http://yowconference.com.au/slides/yowlambdajam2015/Kmett-DiscriminationIsWrong.pdf | |
*/ | |
object MonoidalCategoriesForCategoryOfScalaTypes { | |
import scala.language.higherKinds | |
trait Bifunctor[P[_,_]] { | |
def bimap[A, B, C, D](f: A => B, g: C => D): P[A, C] => P[B, D] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.language.higherKinds | |
/* | |
Mainline Profunctor Heirarchy for Optics: https://r6research.livejournal.com/27476.html | |
Profunctor Optics: The Categorical Approach - Bartosz Milewski: https://www.youtube.com/watch?v=l1FCXUi6Vlw | |
*/ | |
object ProfunctorOpticsSimpleImpl { | |
trait Functor[F[_]] { | |
def map[A, B](x: F[A])(f: A => B): F[B] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait Interact[A] | |
case class Ask(prompt: String) | |
extends Interact[String] | |
case class Tell(msg: String) | |
extends Interact[Unit] | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait λ { | |
type α | |
} | |
trait Functor extends λ { | |
type α <: λ | |
def map[A,B](x: α { type α = A })(f: A => B): α { type α = B } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._, Scalaz._ | |
// Adjunction between `F` and `G` means there is an | |
// isomorphism between `A => G[B]` and `F[A] => B`. | |
trait Adjunction[F[_],G[_]] { | |
def leftAdjunct[A, B](a: A)(f: F[A] => B): G[B] | |
def rightAdjunct[A, B](a: F[A])(f: A => G[B]): B | |
} | |
// Adjunction between free and forgetful functor. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Showing with Kind-Polymorphism the evidence that Monad is a monoid in the category of endofunctors */ | |
object Test extends App { | |
/** Monoid (https://en.wikipedia.org/wiki/Monoid_(category_theory)) | |
* In category theory, a monoid (or monoid object) (M, μ, η) in a monoidal category (C, ⊗, I) | |
* is an object M together with two morphisms | |
* | |
* μ: M ⊗ M → M called multiplication, | |
* η: I → M called unit | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
swap (a, b) = (b, a) | |
class Profunctor p where | |
dimap :: (aa -> a) -> (b -> bb) -> p a b -> p aa bb | |
lmap :: (aa -> a) -> p a b -> p aa b | |
lmap f = dimap f id | |
rmap :: (b -> bb) -> p a b -> p a bb | |
rmap = dimap id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
import Control.Applicative | |
import Data.Char | |
import Data.List (intersperse) | |
import Data.Monoid hiding (All, Any) | |
import Data.Foldable hiding (all, any) | |
import Prelude hiding (all, any) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS_GHC -Wall #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE PatternSynonyms #-} | |
{-# LANGUAGE BangPatterns #-} | |
{-# LANGUAGE LambdaCase #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE StandaloneDeriving #-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz.{Comonad, Monad} | |
import scalaz.{Arrow, Contravariant, Profunctor} | |
import scalaz.{Lan, Ran} | |
object AnyAndNothingInstances { | |
// Monad | |
// https://twitter.com/runarorama/status/1085383309969014784 | |
type FYea[A] = Any |
OlderNewer