Skip to content

Change types in traverseArrayImpl to be more truthful#142

Merged
thomashoneyman merged 1 commit into
purescript:masterfrom
cdepillabout:traversableArrayImpl-type
Mar 10, 2022
Merged

Change types in traverseArrayImpl to be more truthful#142
thomashoneyman merged 1 commit into
purescript:masterfrom
cdepillabout:traversableArrayImpl-type

Conversation

@cdepillabout
Copy link
Copy Markdown
Contributor

@cdepillabout cdepillabout commented Oct 18, 2021

Description of the change

This PR changes the types of traverseArrayImpl to be more true to how they are actually used.

This changes traverseArrayImpl from

traverseArrayImpl
  :: forall m a b
   . (m (a -> b) -> m a -> m b)
  -> ((a -> b) -> m a -> m b)
  -> (a -> m a)
  -> (a -> m b)
  -> Array a
  -> m (Array b)

to

traverseArrayImpl
  :: forall m a b
   . (forall x y. m (x -> y) -> m x -> m y)
  -> (forall x y. (x -> y) -> m x -> m y)
  -> (forall x. x -> m x)
  -> (a -> m b)
  -> Array a
  -> m (Array b)

traverseArrayImpl is called like the following:

instance traversableArray :: Traversable Array where
   traverse = traverseArrayImpl apply map pure  

Here the apply, map, and pure functions are all polymorphic in their arguments (the x and y in the changed type above), so this new type for traverseArrayImpl is more true.

Also, in the FFI files for traverseArrayImpl, apply, map, and pure are used as if they are polymorphic. For instance, pure is used on an Array, not an a:


Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@cdepillabout
Copy link
Copy Markdown
Contributor Author

cdepillabout commented Oct 18, 2021

Added the change to the changelog's "Unreleased" section with a reference to this PR

Does this change require an addition to the changelog?

While changing the type of traverseArrayImpl would be a breaking change for backend implementors, I don't think it is actually possible to implement traverseArrayImpl with the current, non-polymorphic type. So I imagine alternative backend implementors have already taken this discrepancy into account. In practice, I doubt any of the alternative backends will have to make any changes because of this PR.

Copy link
Copy Markdown
Member

@thomashoneyman thomashoneyman left a comment

Choose a reason for hiding this comment

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

@cdepillabout I think you're right about the changes wrt other backends, and I'm on board.

@thomashoneyman thomashoneyman merged commit 1e1b752 into purescript:master Mar 10, 2022
@cdepillabout cdepillabout deleted the traversableArrayImpl-type branch March 11, 2022 00:10
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