-
Notifications
You must be signed in to change notification settings - Fork 26
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
Features/string library #250
Features/string library #250
Conversation
I should add that the only warning right now is that the old |
Rebased and ready for review! |
d8fcab5
to
8813d0d
Compare
it complains that there would be conflicts and cannot be merged |
@kikofernandez: Yes, because somebody decided to rebase plenary again today at half past four... ;) |
the problem for the failed test is that the
line I can push the refactoring to |
@kikofernandez Had the change locally. Pushed now! |
I totally agree, but it's a problem of error reporting in general. Could you add it to the wailing wall in the encore-lang slack channel? |
since we are using |
is there any way where:
which typechecks could be written without the surrounding parenthesis such as:
|
@@ -649,11 +652,14 @@ expr = unit | |||
return $ Peer (meta pos) ty | |||
print = do pos <- getPosition | |||
reserved "print" | |||
val <- expression | |||
return $ Print (meta pos) "{}\n" [val] | |||
arg <- option [] ((:[]) <$> expression) |
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 change arg <- option [] ((:[]) <$> expression)
allows us to write:
let x = something in
print;
is there any reason for allowing this behavior?
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.
Writing only print
will print a newline. This is how Python does it (although that might not me motivation to have it like that).
|
after this is clarified, I think this could be merged (previous squashing of the commits mentioned in the initial commit) |
Do you mean the scribble stuff, or some kind of per-method-documentation?
Ah, no... This is a bug in the desugaring. What is going on is that |
This is a general parsing issue, not related to strings. Use the wailing wall (or create an issue). |
|
Fix to |
In this case, it makes sense to mention string in the language documentation. In general, however, I think we should not aim to add all stdlib to the language documentation. The stdlib has its own documentation (which the language doc may of course link to) |
@kaeluka: 👍 |
8813d0d
to
4442564
Compare
During the typechecking phase you can now emit warnings which will be printed at compile time. Warnings are not arbitrary strings (like errors) but must be explicitly defined as constructors of the type `Warning`, together with the corresponding case for showing the warning. Right now there is only one warning `StringDeprecatedWarning`, which is given when the type `string` is used. It is produced in `Util.hs` in the following code: ``` | isStringType ty = do tcWarning StringDeprecatedWarning return ty ``` I believe we should move to this system for errors as well as it centralizes all possible errors that can be thrown. For example, we would then write `assertSubtypeOf` (in `Typechecker.hs`) as ``` assertSubtypeOf :: Type -> Type -> TypecheckM () assertSubtypeOf sub super = unlessM (sub `subtypeOf` super) $ tcError $ TypeMismatch sub super ```
It turns out that one of the implementations of split had a bug that would produce incorrect results. It would only be used when patterns of certain lengths were used, and the test case that triggered that bug was commented out(!). I fixed this by removing the buggy implementation.
This is related to issue #282. The affected methods were `string_from_array`, `to_array` and `split`. New test cases have been added.
@vhphuc If you feel happy with the changes addressing your comments, you can merge this pull request by hitting the big green button below :) |
I recall there was some discussion on the behavior of |
I would be more surprised if concatenating with the empty string somehow added "more" empty string to the string. Doing so would violate the monoid identity(?) rule:
|
Compare with natural numbers and addition: It is generally the case that |
There's nothing odd on the behaviour of |
One could also argue that
This would also interplay nicely with the expected property |
If you agree with this I will create an issue for it so that it can be fixed after the final PRs to |
I am possibly too biased, but |
@albertnetymk Surely you must agree that |
@albertnetymk's invariant |
Since this PR has been merged already, maybe we should create an issue so the discussion doesn't get lost? |
@EliasC Sure, appending empty string is a no-op for the original string. @supercooldave Indeed, thanks. |
Wait a sec. @supercooldave I think |
@albertnetymk: That may well be what the code does, but is that what the specification means? |
Regardless of the implementation of Python it seems agrees with this: Python
Most languages I've tried seem to not even have such a method, maybe because they couldn't agree within the development teams? :) |
+1 |
@EliasC @supercooldave For |
Thanks! I missed this!
I also think that we should have the same semantics as Python does (as I have argued above). |
Currently, we do NOT, right? |
We should have a clear specification and the implementation should abide (like The Dude). |
@albertnetymk: Currently we do not. |
This is @TobiasWrigstad and my work on adding a string library. It replaces the old type
string
with a passive class typeString
which has similar functionality to the immutable strings of Java. Writing"Hello"
is now syntactic sugar fornew String("Hello")
, where the string argument is the embedded C typechar*
. The class itself can be found inbundles/standard/String.enc
, which is the suggested location for the standard library.Other notable additions in this PR is the
char
type (written as'a'
) and the ability to give warnings during typechecking. See the commit history for more details.I've tried to prune the history somewhat, but it could probably be squashed into even fewer commits. However, I think the full log makes it easier to see what has been done when doing the review (please let me know if you disagree). When this is deemed ready for merging, I will squash the history into two or three commits.