{"action":"created","issue":{"url":"https://api.github.com/repos/scalaz/scalaz-io/issues/3","repository_url":"https://api.github.com/repos/scalaz/scalaz-io","labels_url":"https://api.github.com/repos/scalaz/scalaz-io/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/scalaz/scalaz-io/issues/3/comments","events_url":"https://api.github.com/repos/scalaz/scalaz-io/issues/3/events","html_url":"https://github.com/scalaz/scalaz-io/issues/3","id":324719713,"number":3,"title":"Church-encoded Maybe","user":{"login":"ktonga","id":1324947,"avatar_url":"https://avatars1.githubusercontent.com/u/1324947?v=4","gravatar_id":"","url":"https://api.github.com/users/ktonga","html_url":"https://github.com/ktonga","followers_url":"https://api.github.com/users/ktonga/followers","following_url":"https://api.github.com/users/ktonga/following{/other_user}","gists_url":"https://api.github.com/users/ktonga/gists{/gist_id}","starred_url":"https://api.github.com/users/ktonga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktonga/subscriptions","organizations_url":"https://api.github.com/users/ktonga/orgs","repos_url":"https://api.github.com/users/ktonga/repos","events_url":"https://api.github.com/users/ktonga/events{/privacy}","received_events_url":"https://api.github.com/users/ktonga/received_events","type":"User","site_admin":false},"labels":[{"id":938355734,"url":"https://api.github.com/repos/scalaz/scalaz-io/labels/question","name":"question","color":"d876e3","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-05-20T15:57:37Z","updated_at":"2018-05-21T03:01:49Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"@jdegoes you in scalaz/scalaz#1798 specify that replacements for `Maybe` and `\\/` should be church-encoded. Why exactly? as opposed to sum types.\r\n\r\nSo 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.\r\n\r\n```scala\r\nfinal class Perhaps[A, B] private (val perhaps: (B, A => B) => B) extends AnyVal {\r\n  def map[C](g: A => C): Perhaps[C, B] = new Perhaps((b, f) => perhaps(b, f.compose(g)))\r\n  def toOption: Option[A] = perhaps(None.asInstanceOf[B], a => Some(a).asInstanceOf[B]).asInstanceOf[Option[A]]\r\n}\r\n\r\nobject Perhaps {\r\n  def present[A, B](a: A): Perhaps[A, B] = new Perhaps((_, f) => f(a))\r\n  def absent[A, B]: Perhaps[A, B] = new Perhaps((b, _) => b)\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/scalaz/scalaz-io/issues/comments/390540733","html_url":"https://github.com/scalaz/scalaz-io/issues/3#issuecomment-390540733","issue_url":"https://api.github.com/repos/scalaz/scalaz-io/issues/3","id":390540733,"user":{"login":"ktonga","id":1324947,"avatar_url":"https://avatars1.githubusercontent.com/u/1324947?v=4","gravatar_id":"","url":"https://api.github.com/users/ktonga","html_url":"https://github.com/ktonga","followers_url":"https://api.github.com/users/ktonga/followers","following_url":"https://api.github.com/users/ktonga/following{/other_user}","gists_url":"https://api.github.com/users/ktonga/gists{/gist_id}","starred_url":"https://api.github.com/users/ktonga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktonga/subscriptions","organizations_url":"https://api.github.com/users/ktonga/orgs","repos_url":"https://api.github.com/users/ktonga/repos","events_url":"https://api.github.com/users/ktonga/events{/privacy}","received_events_url":"https://api.github.com/users/ktonga/received_events","type":"User","site_admin":false},"created_at":"2018-05-21T03:01:49Z","updated_at":"2018-05-21T03:01:49Z","author_association":"CONTRIBUTOR","body":"@jdegoes how you like this encoding?\r\n\r\n```scala\r\n  final case class FromEA[E, A](err: E => IO[E, A], succ: A => IO[E, A])\r\n  \r\n  final def absolve[E, A, B](f: FromEA[E, A] => B => IO[E, A])(v: IO[E, B]): IO[E, A] =\r\n    v.flatMap(f(FromEA[E, A](IO.fail, IO.now)))\r\n```"}}
{"actor":{"display_login":"ktonga"}}