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

Add Plutus implementation of mapM_ (fix #3203). #3209

Merged
merged 2 commits into from
May 25, 2021
Merged

Conversation

ghost
Copy link

@ghost ghost commented May 18, 2021

The problem in #3203 is that PlutusTx.Prelude re-exports Prelude.mapM_ which fails to compile. The fix is to add Plutus's own implementation.


Pre-submit checklist:

  • Branch
    • Commit sequence broadly makes sense
    • Key commits have useful messages
    • Relevant tickets are mentioned in commit messages
    • Formatting, materialized Nix files, PNG optimization, etc. are updated
  • PR
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

Pre-merge checklist:

  • Someone approved it
  • Commits have useful messages
  • Review clarifications made it into the code
  • History is moderately tidy; or going to squash-merge

@ghost ghost requested review from michaelpj and j-mueller May 18, 2021 08:22
{-# INLINABLE mapM_ #-}
mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
mapM_ f = foldr c (return ())
-- See Note [List fusion and continuations in 'c']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this note? And does it apply to Plutus?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at https://hackage.haskell.org/package/base-4.15.0.0/docs/src/Data-Foldable.html#mapM_

Yeah, not sure about Plutus, removed.

@@ -201,3 +209,10 @@ find p = getFirst . foldMap (\ x -> First (if p x then Just x else Nothing))
(#.) :: Coercible b c => (b -> c) -> (a -> b) -> (a -> c)
(#.) _f = coerce
{-# INLINE (#.) #-}

{-# INLINABLE mapM_ #-}
mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haddocks: "Plutus version of 'Control.Monad.mapM_'

We should probably also add mapM

Copy link
Author

@ghost ghost May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fixed, but to Data.Foldable.mapM_ because that's the original location. And mapM is already in PlutusTx.Traversable.

@ghost ghost requested a review from j-mueller May 19, 2021 14:12
@ghost ghost force-pushed the plutus-prelude-mapm branch from fd5e2a9 to 338c855 Compare May 25, 2021 07:21
@ghost
Copy link
Author

ghost commented May 25, 2021

@michaelpj I have rebased the PR, should be possible to merge now.

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 this pull request may close these issues.

2 participants