-
Couldn't load subscription status.
- Fork 1.4k
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
@jdegoes you in scalaz/scalaz#1798 specify that replacements for Maybe and \/ should be church-encoded. Why exactly? as opposed to sum types.
So far I've got this, but dunno how to get rid of B type parameter, it should be using some sort of Haskell's forall but I can't figure out how to express that in Scala.
final class Perhaps[A, B] private (val perhaps: (B, A => B) => B) extends AnyVal {
def map[C](g: A => C): Perhaps[C, B] = new Perhaps((b, f) => perhaps(b, f.compose(g)))
def toOption: Option[A] = perhaps(None.asInstanceOf[B], a => Some(a).asInstanceOf[B]).asInstanceOf[Option[A]]
}
object Perhaps {
def present[A, B](a: A): Perhaps[A, B] = new Perhaps((_, f) => f(a))
def absent[A, B]: Perhaps[A, B] = new Perhaps((b, _) => b)
}Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested