Last active
August 29, 2015 14:04
-
-
Save wheaties/628c3248eb1c6f5abe1e to your computer and use it in GitHub Desktop.
HMonad Idea
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 HZero[P <: Poly, A1, A2]{ | |
| type Out | |
| val value: Out | |
| } | |
| object HZero{ | |
| implicit def apply[P <: Poly, A1, A2](implicit z: Zero[P, A1, A2]): Aux[P, A1, A2, z.Out] = z | |
| type Aux[P <: Poly, A1, A2, Out0] = HZero[P, A1, A2]{ type Out = Out0 } | |
| implicit def mkZero[P <: Poly, A1, A2, Z](implicit ev: Case2.Aux[P, A1, A2, Z], m: Monad[Z]) = | |
| new HZero[P, A1, A2]{ | |
| type Out = Z | |
| val value = m.zero | |
| } | |
| } | |
| //How to express return and bind? No F[_] type if we don't have a defined type to work on | |
| class HMonad[P <: Poly](p: P){ | |
| def zero[A1, A2](implicit z: HZero[P, A1, A2]): z.Out = z.value | |
| def append[A1, A2](arg1: A1, arg2: A2)(implicit ev: Case2[P, A1, A2]): ev.Result = ev(arg1, arg2) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now how to get it to obey the Monad laws? Bind? Return? Ugh!