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

Special syntax for fully-applied primitive operations #243

Merged
merged 9 commits into from
Dec 18, 2020

Conversation

yannham
Copy link
Member

@yannham yannham commented Dec 8, 2020

Close #228. Use a specific syntax for fully applied built-in operators, %operator%, and wrap this primitive version in vanilla functions of the standard library.

This has the unfortunate consequence described in #226, that is that wrapped operator does not behave as unwrapped operator with respect to typing, but this is a separate topic that needs to be addressed anyway.

This also led to #244. This PR currently assigns correct but less ergonomic types - the ones with Dyn - to primitive operators wrapped in the standard library, while the actual primitive ones stay polymorphic. We'll have to resolve this discrepancy together with #244.

@yannham yannham marked this pull request as ready for review December 8, 2020 17:46
@yannham yannham mentioned this pull request Dec 8, 2020
@yannham yannham force-pushed the task/primitive-operators-representation branch from e1cb155 to 9fb8df7 Compare December 9, 2020 14:40
Comment on lines +195 to +199
self.load_stdlib(
"<stdlib/records.ncl>",
nickel_stdlib::RECORDS,
&mut global_env,
)?;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe stdlib.rs should export a list of all its Nickel modules. I feel that it's rather impractical to have to add said modules in two different files.

Copy link
Member Author

Choose a reason for hiding this comment

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

True. I'm currently reworking the program module to prepare for the REPL anyway, I will do that.

concat : List -> List -> List = fun l1 l2 => l1 @ l2;

foldl : forall a. (a -> Dyn -> a) -> a -> List -> a =
fun f fst l =>
if length l == 0 then
if %length% l == 0 then
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to this PR, but I hope that %length% l is O(1). Otherwise foldl (and fold) as written here is quadratic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, list are currently implemented as vectors so length is O(1). I suspect this was written because at that time equality was implemented only for numbers though, so l == [] is probably more future-proof.

@yannham yannham merged commit f9d0c1c into master Dec 18, 2020
@yannham yannham deleted the task/primitive-operators-representation branch December 18, 2020 10:52
This pull request was 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 this pull request may close these issues.

Better handling of primitive functions and operators
2 participants