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

foldr1 does not replace Data.Foldable ( foldr1 ) #373

Closed
Anton-Latukha opened this issue Mar 21, 2021 · 2 comments
Closed

foldr1 does not replace Data.Foldable ( foldr1 ) #373

Anton-Latukha opened this issue Mar 21, 2021 · 2 comments

Comments

@Anton-Latukha
Copy link

Anton-Latukha commented Mar 21, 2021

HNix is a pretty big project. And the migration to relude went smooth, the migration took ~2d of work for everything, and also to debug this issue.

https://github.com/haskell-nix/hnix/blob/cd02c6dd59105ccbfb36218fba3b0bce3c8c77ad/src/Nix/Parser.hs#L607-L608

manyUnaryOp :: MonadPlus f => f (a -> a) -> f (a -> a)
manyUnaryOp f = foldr1 (.) <$> some f

Data.Foldable ( foldr1 ) would be:
Screenshot-2021-03-21-21:03:30

If we to use relude foldr1 for that we would receive:

src/Nix/Parser.hs:609:32: error:
    • Couldn't match type ‘[a -> a]’ with ‘a0 -> b0’
      Expected type: f (a0 -> b0)
        Actual type: f [a -> a]
    • In the second argument of ‘(<$>)’, namely ‘some f’
      In the expression: foldr1 (.) <$> some f
      In an equation for ‘manyUnaryOp’:
          manyUnaryOp f = foldr1 (.) <$> some f
    • Relevant bindings include
        f :: f (a -> a) (bound at src/Nix/Parser.hs:609:13)
        manyUnaryOp :: f (a -> a) -> f (a -> a)
          (bound at src/Nix/Parser.hs:609:1)
    |
609 | manyUnaryOp f = foldr1 (.) <$> some f
    |                                ^^^^^^

Screenshot-2021-03-21-21:04:43

This is the only thing that was on the Relude side during migration. At first, I've with GHC thought that is some Skolem Existential thing, because was looking from the Relude function side.

But then, nope, Reludes foldr1 asks for a base case, while Foldable one is not.

@chshersh
Copy link
Contributor

I mentioned some challenges in implementing foldr1 in the following comment:

In short, changing the type would be nice but the implementation has some challenges and requires a major version bump up.

Anton-Latukha added a commit to Anton-Latukha/relude that referenced this issue Mar 25, 2021
While migrating pretty big codebase (HNix) `foldr1` replacement is the only
place I tripped over and was puzzled a bit, the solution was simple, but harder
to see because difference was unexpected.

Since `relude` is very transparent in migration. It is good to document where
the API differences is, to guide people during migration and during use.

For more info:
kowainik#373
kowainik#307 (comment)
@Anton-Latukha
Copy link
Author

Ok.
Considering this as seen, discussed and closed.

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

Successfully merging a pull request may close this issue.

2 participants