WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Are cats.mtl.Handle[F[_], E] and cats.ApplicativeError[F[_], E] the same abstraction? #646

@benhutchison

Description

@benhutchison

Are cats.mtl.Handle[F[_], E] and cats.ApplicativeError[F[_], E] the same abstraction?

I can't see a meaningful difference between them. Handle includes code to derive itself from ApplicativeError. The reverse derivation also seems possible. So they appear isomorphic.

Which suggests the machinery for submarine error propagation could equally be supported for ApplicativeError, potentially reaching the wider audience of Cats users.

It also seems confusing, to me at least, to have two isomorphic type-classes in the same ecosystem.

There is also cats.MonadError, a subclass of ApplicativeError which is often more useful in practice, because it permits sequencing operations with flatMap - a common requirement of application code.

MonadError[F, E] suffices to express fallible-but-othewise-pure computations and neatly abstracts across concrete effects Either, and the more powerful cats.effect.IO (with submarines to permit non-Throwable error types). So the ability to derive Handle+Monad=>MonadError seems valuable.

given [F[_]: Monad as m, E](using h: Handle[F, E]): MonadError[F, E] = new MonadError:
  def pure[A](x: A): F[A] = h.applicative.pure(x)
  def handleErrorWith[A](fa: F[A])(f: E => F[A]): F[A] = h.handleWith(fa)(f)
  def raiseError[A](e: E): F[A] = h.raise(e)
  def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] = m.flatMap(fa)(f)
  def tailRecM[A, B](a: A)(f: A => F[Either[A, B]]): F[B] = m.tailRecM(a)(f)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions