-
Notifications
You must be signed in to change notification settings - Fork 323
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
Convert vector elements when needed #7271
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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!" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 fold
s over the Vector
, we request each element to be Hello
or converted to Hello
.
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
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: