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

Convert vector elements when needed #7271

Merged
merged 1 commit into from
Jul 12, 2023

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Jul 12, 2023

Pull Request Description

Adds a test case demonstrating the use of automatic conversions when processing vector elements.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code has been tested:
    • Unit tests have been written where possible.

@JaroslavTulach JaroslavTulach added -compiler -libs Libraries: New libraries to be implemented labels Jul 12, 2023
@JaroslavTulach JaroslavTulach self-assigned this Jul 12, 2023
Copy link
Member Author

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

The fact that the new test case works demonstrates that logic that locates conversion is good. Hello.formulate knows nothing about Foo or Bar types, yet the runtime finds the appropriate conversions that are defined next to definition of Foo and/or Bar.

type Hello
Say (msg:Text)

formulate : Vector Hello -> Text
Copy link
Member Author

Choose a reason for hiding this comment

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

First of all there is a static method that operates on a Vector with Hello elements.

@@ -115,4 +116,11 @@ spec =
Test.specify "should not allow currying" <|
Panic.recover Any (Foo.from) . catch Any .to_display_text . should_equal "Conversion currying without `that` argument is not supported."

Test.specify "Use conversions to in Conversion_Use module" <|
Hello.formulate [ Hello.Say "Proper", Hello.Say "Type" ] . should_equal "ProperType"
Hello.formulate [ Foo.Value "Perform", Bar.Value "Conversion" ] . should_equal "PERFORM conversion!"
Copy link
Member Author

Choose a reason for hiding this comment

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

This line invokes the static formulate method with non-Hello instances, but these instances have conversions methods to Hello defined in this module. See below...


formulate : Vector Hello -> Text
formulate arr =
process (t:Text) (h:Hello) = t + h.msg
Copy link
Member Author

Choose a reason for hiding this comment

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

By using ascribed arguments in a function that folds over the Vector, we request each element to be Hello or converted to Hello.

Copy link
Member

@jdunkerley jdunkerley left a comment

Choose a reason for hiding this comment

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

Thanks for this test case - this looks awesome.
Will try it on a couple of Table methods.

@JaroslavTulach JaroslavTulach added the CI: Ready to merge This PR is eligible for automatic merge label Jul 12, 2023
@mergify mergify bot merged commit 724a788 into develop Jul 12, 2023
@mergify mergify bot deleted the wip/jtulach/ConvertingVectorElementsWhenNeedd branch July 12, 2023 13:05
Copy link
Member

@radeusgd radeusgd left a comment

Choose a reason for hiding this comment

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

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-compiler -libs Libraries: New libraries to be implemented CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants