Last active
December 14, 2015 03:49
-
-
Save arosien/5024141 to your computer and use it in GitHub Desktop.
shapes
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
| (A => B) => A => B // function | |
| (A => B) => F[A] => F[B] // Functor.fmap | |
| Z[A => B] => Z[A] => Z[B] // Applicative.apply | |
| (A => M[B]) => M[A] => M[B] // Monad.bind | |
| (A => B) apply A: B // Function1.apply | |
| F[A] fmap (A => B): F[B] // Functor.fmap | |
| Z[A] <*> Z[A => B]: Z[B] // Applicative.apply | |
| M[A] >>= (A => M[B]): M[B] // Monad.bind | |
| K[M, A, B] >=> (B => M[C]): K[M, A, C] // Kleisli compose | |
| trait Functor[F[_]] { | |
| def fmap[A, B](a: F[A], f: A => B): F[B] | |
| } | |
| trait Applicative[A[_]] extends Functor[A] { | |
| def <*>[A, B](a: Z[A], f: Z[A => B]): Z[B] | |
| } | |
| val za: Z[A] | |
| val zb: Z[B] | |
| /* | |
| zb <*> (za fmap f) | |
| Z[B] <*> (Z[A] fmap (A => B => C)) | |
| Z[B] <*> (Z[B => C]) | |
| Z[C] | |
| */ | |
| val f: (A => B => C) | |
| val zc: Z[C] = zb <*> (za fmap f) | |
| /* | |
| Order doesn't matter! | |
| za <*> (zb fmap f2) | |
| Z[A] <*> (Z[B] fmap (B => A => C)) | |
| Z[A] <*> (Z[A => C]) | |
| Z[C] | |
| */ | |
| val f2: (B => A => C) | |
| val zc: Z[C] = za <*> (zb fmap f2) | |
| /* | |
| * Sources: | |
| * | |
| * Functors and things using Scala, http://blog.tmorris.net/posts/functors-and-things-using-scala/ | |
| * Lifting, http://blog.tmorris.net/posts/lifting/ | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
fmapoperation is sometimes calledlift1It corresponds to lifting an arity-1 function into an environment (F). See http://blog.tmorris.net/posts/lifting/Lines 13-19 do not accurately represent the operation under examination, since they omit the initial argument (
F[A]). The use ofthisis not constrained enough. However, they are on the right track and with some modification, can be made more accurate.