-
Notifications
You must be signed in to change notification settings - Fork 211
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
WIP: Implement as Location
import syntax
#449
Conversation
We agreed that it does not make sense to specify a hash for a url used |
It turns out, I overlooked one part of url syntax, namely, I have actually implemented it already, will push later because no wifi. |
I am not really sure what to do with urls. I am now starting to think that adding a dependency on some library for handling urls might be not worth it. What do you think? |
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 great! I can help with the matching change to the standard (hopefully tomorrow)
@@ -352,6 +357,14 @@ data Expr s a | |||
| TextLit (Chunks s a) | |||
-- | > TextAppend x y ~ x ++ y | |||
| TextAppend (Expr s a) (Expr s a) | |||
-- | > FilePath ~ FilePath | |||
| FilePath |
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.
Perhaps shorten the name FilePath
to File
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.
Well, I don’t know, are you sure? I feel that it will be somewhat more ambiguous. Also, currently it nicely corresponds to the Haskell type, as other primitive types (e.g. Integer
, Text
).
buildExprF FilePath = | ||
"FilePath" | ||
buildExprF Url = | ||
"Url" |
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.
Perhaps Url
should be capitalized as URL
since it is an acronym
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.
Oh, sorry, I always capitalise this way, as most coding guidelines suggest using camel case with acronyms, so I didn’t even think about it.
Anyway, I can capitalise the text representation of the type, but if I change the constructor itself, then it will conflict with URL
from ImportType
. I guess, I can add Import
as a prefix to constructors of ImportType
. What do you think?
src/Dhall/Import.hs
Outdated
URL prefix file suffix maybeHeaders -> do | ||
m <- needManager | ||
instance Show IllegalImportType where | ||
show EnvAsLocation = _ERROR <> ": env cannot be imported as a location" |
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.
s/env/an environment variable/
and s/as location/❰as Location❱/
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.
✅
src/Dhall/Diff.hs
Outdated
mismatch l r | ||
diffExprF l r@(FilePathLit _) = | ||
mismatch l r | ||
-- TODO: Diff maybeHeaders? |
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.
As we discussed offline, we can probably have import resolution fail if the user specifies both using
and as Location
Oh, one other thing: don't forget to mention the |
By the way, I finally read some code around the parts I changed (😄) and I should point out that new relative path literals (somewhat) violate referential transparency: the check that local files cannot be imported from a remote one is done only when actually reading, so it is not performed for On the one hand, it makes perfect sense for the cases when, e.g. some sort of default configuration is loaded from a remote URL and paths to other files in it are resolved relative to current directory and it probably doesn’t harm too much, since the referred files are not interpreted and even not read. On the other hand, your notion of referential transparency seems to be a good idea. I’m not sure what to do. |
Wait, no, it is resolved relative to the URL of the file that contains it, not to current directory 😕. |
@kirelagin: What use case do you have in mind for this? I ask because in dhall-lang/dhall-lang#71 one of the ideas was that the import would actually be checked to see if it was valid The reason I mention this is that if you validate the import tagged with |
Well, I have a felling (although, I have no evidence to back this claim) that software typically wants to just read a path from its config and then deal with any issues itself (e.g. if a database does not exist, create it) instead of getting an exception from its configuration “parser”. |
@kirelagin: Then let's leave it as is for now, but with one change: don't reject custom headers or a semantic integrity check. The idea is that maybe later we'll add a |
Is there just @Gabriel439's last comment to address before this can get merged? I'm really keen to have this feature. |
I’m sorry, I got very distracted from this PR. I can fix this PR hopefully in the next few days, but I am not sure I will have time to update the standard, so any help is really welcome. |
Yeah, the standard is the big issue. This has to be standardized before the Haskell implementation can be changed You don't necessarily need to put up a pull request with the changes to the semantics and grammar. Just open an issue against the |
I'm closing this since it's drifted quite a bit from |
A fix for dhall-lang/dhall-lang#71.
This PR adds two new types:
FilePath
Url
and literals for them. The syntax is
./some/path as Location
andhttps://example.com/url as Location
respectively.Trying to use an
env:
import withas Location
is an error.TODO:
Take headers which come from hashes (?) into account in diff.Uri
type forUrl
literals instead of currentText
?