Skip to content

Instantly share code, notes, and snippets.

@wheaties
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save wheaties/628c3248eb1c6f5abe1e to your computer and use it in GitHub Desktop.

Select an option

Save wheaties/628c3248eb1c6f5abe1e to your computer and use it in GitHub Desktop.
HMonad Idea
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)
}
@wheaties
Copy link
Copy Markdown
Author

wheaties commented Aug 6, 2014

Now how to get it to obey the Monad laws? Bind? Return? Ugh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment