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
Prelude: add functions version of built-in operators #1037
Conversation
This change adds the `add` function for Natural.
Could you say something about the motivation for this addition, @TristanCacqueray? |
This can be use to do function composition with addition, for example to generate a list of natural starting from one, we could write: Prelude.List.generate count Natural (Prelude.Natural.add 1) Instead of: Prelude.List.generate count Natural (\(idx : Natural) -> idx + 1)) |
@TristanCacqueray: I think the main issue is that if we add this we would need to add functions for other operators for consistency, but then we'd run into naming conflicts (since |
I see, then I guess it's better to keep operator out of the Prelude. |
Maybe we could add a |
@lisael: Yeah, I would be fine with something like that! |
Alright I can work on that, so:
|
+1/2 for There are some existing names that we can but don't have to reuse in the grammar: dhall-lang/standard/dhall.abnf Lines 804 to 818 in 5fde8ef
Also, don't forget |
So Operator.TextAppend (++) and Operator.ListAppend (#) ? |
Another option is that we could name the fields after the operators by quoting the operators with bacticks. In other words, you could do: Prelude.Operator.`==` However, I'd also be fine with the current names, too |
Another shower thought is that the operators that are not commutative (namely let appendText
: Text → Text → Text
= λ(m : Text) → λ(n : Text) → n ++ m
let prependText
: Text → Text → Text
= λ(m : Text) → λ(n : Text) → m ++ n Note that the name of the function becomes Usage: let hostnameToFqdn = λ(hostname : Text) → appendText ".example.com" hostname |
I love this idea! This eliminates the problem that some of the current names might be hard to remember. For example @lisael I think we need to find a balance between adding quality-of-life improvements and keeping the Prelude at a size where it's not overly hard to navigate and maintain. Performance is also a relevant concern. When considering API enhancements in Haskell libraries I sometimes try use the Fairbairn threshold. So I'm not a fan of adding flipped versions of functions. We could rather consider adding something like Prelude.Function.flip : ∀(a : Type) → ∀(b : Type) → (a → b) → b → a if anyone would want to use that. Also, do we really want to have a version with the |
Alright, next commit uses the operator symbols without the extensionless files. |
Thanks @TristanCacqueray! :) I'm vaguely concerned about filenames like Are there any filename experts present? ;) |
https://stackoverflow.com/a/35352640/1013393 indicates that |
I named the file after the symbols as a test, but even if that works, I think that can be a source of unexpected problems. So either we pick type neutral name for the filename (and keep the operator symbols in the package.dhall record), either we could pack all the definition directly in the package.dhall record. |
@TristanCacqueray: I think it would be fine to pack all of the definitions directly in the |
I haven't check how the single file doc render though. Are the dhall-docs output available through hydra build logs? |
@TristanCacqueray: Not for this repository. We build |
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.
Looks pretty good! Nearly done, I think.
Maybe it would be more conventional to offer these functions via |
Thank you all for the feedbacks, I hope I get the suggestions right in the last commits :-) Please do let me know otherwise. |
This change adds the
add
function for Natural.