Skip to content

Instantly share code, notes, and snippets.

@jonsterling
Created August 28, 2012 15:12
Show Gist options
  • Save jonsterling/3498951 to your computer and use it in GitHub Desktop.
Save jonsterling/3498951 to your computer and use it in GitHub Desktop.
// Which of these do you find easier to scan?
// This is what I imagine you would prefer. No single-char variable
// names. The purpose of every variable is described to the best of my
// ability, though many parameters are just that: parameters.
implicit def KleisliCategory[MonadParam[_]: Monad]:
Category[({type TypeConstructor[FirstParam,
SecondParam] = Kleisli[MonadParam, FirstParam,
SecondParam])#TypeConstructor] = new Category[({type
TypeConstructor[FirstParam, SecondParam] = Kleisli[MonadParam,
FirstParam, SecondParam]})#Constructor] = {
def identity[ForType] = kleisli(value => value.pure)
def compose[Input, InputOutput, Output](secondFunction:
Kleisli[MonadParam, InputOutput, Output], firstFunction:
Kleisli[MonadParam, Input, InputOutput]) = kleisliCompose(firstFunction,
secondFunction)
}
// This is the original.
implicit def KleisliCategory[M[_]: Monad]: Category[({type λ[α, β]=Kleisli[M, α, β]})#λ] = new Category[({type λ[α, β]=Kleisli[M, α, β]})#λ] {
def id[A] = ☆(_ η)
def compose[X, Y, Z](f: Kleisli[M, Y, Z], g: Kleisli[M, X, Y]) = f <=< g
}
// Some things I prefer about the longer version: the unicode star is
// stupid, as is using an eta for the `pure` natural transformation.
// The ({type λ[α, β]=...})#λ nonsense is an unfortunate consequence of
// the Scala language. Nobody really likes that, but there's not a whole
// lot that can be done to improve it.
@jonsterling
Copy link
Author

Well put.

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