Skip to content

Find generic versions of the same function #399

@newhoggy

Description

@newhoggy

I tried searching for this in Hoogle and found no matches:

Monad m => (e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a

I then implemented it like this:

onLeft :: Monad m => (e -> ExceptT x m a) -> ExceptT x m (Either e a) -> ExceptT x m a
onLeft h f = f >>= either h pure

Inferring the type signature I get this:

onLeft :: Monad m => (a -> m b) -> m (Either a b) -> m b
onLeft h f = f >>= either h pure

The inferred type signature is one that actually yields results:

Monad m => (a -> m b) -> m (Either a b) -> m b

fromRightM :: Monad m => (a -> m b) -> m (Either a b) -> m b
fromEitherMM :: Monad m => (e -> m a) -> m (Either e a) -> m a
fromEitherOrMM :: Monad m => m (Either e a) -> (e -> m a) -> m a

If Hoogle can somehow infer the generic type signature from the specialised one and put that in the search results, that would help a lot.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions