Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find generic versions of the same function #399

Open
newhoggy opened this issue Jan 20, 2023 · 1 comment
Open

Find generic versions of the same function #399

newhoggy opened this issue Jan 20, 2023 · 1 comment

Comments

@newhoggy
Copy link

newhoggy commented Jan 20, 2023

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.

@ndmitchell
Copy link
Owner

Yep, this would be desirable - but its hard because of the way Hoogle is implemented. Hoogle essentially tries to find things that have the same shape, or the same interesting type names. Because you end up unifying ExceptT x m with m, you have neither the same shape or type names. If you just generatlise then you can generalise in many many ways, and that would be a bit of a combinatorial explosion. For instance, this type aliases with undefined and coerce. I don't have any great ideas for finding what you describe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants