Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Have we discussed the ability to describe grammars within the language? If so, link me to it and close this issue.
I haven't really thought out what I'm suggesting here, but I wonder if the ability to write a grammar in Dhall, and be able to parse
Grammar/parse : Grammar a -> Text -> < error : Text, value : a >
The intent being that you're still dealing with structured data. Ideally, using
As for what level of grammars we'd be able to describe–regular, context-free, context-sensitive, recursively-enumerable–I don't have a requirement. I assume something that doesn't break totality would be a restriction. Text manipulation can stay restricted, I'm not wanting to change that.
I'm not stuck on any of the ideas I presented. Maybe the spirit of this idea would be useful?
To expand @singpolyma’s comment: the first paragraph about text manipulation from your link says:
But (context-free) grammars would provide a trivial way to compute length.
Further down the section, there is an example about how there’s no way in Dhall to construct an
Sorry, I'm having a bit of trouble interpreting these responses. Do these responses mean this idea is not going to happen and we should close the issue? Are these responses providing additional information about this idea to encourage more discussion?
I think a new feature which goes against a stated goal of the language probably needs a fairly strong case in favour to be added.
Some things that might help a case:
So the main reason we try to discourage text manipulation is that we try to push validation to the edge of the system so that Dhall code deals entirely with strongly typed inputs.
The best analogy I can make is that there are two ways to write a type-safe
head :: [a] -> Maybe a
... where you propagate failures downstream. Thee other way is:
head :: NonEmpty a -> a
... where you propagate requirements upstream. Dhall strives to be like the latter idiom: imposing greater requirements on upstream by validating at import time.
The reason I bring this up is that we might be able to support text manipulation or grammars, but only at import-timee. In other words, something like:
./someImport as SomeGrammar
I'm not exactly sure what such a grammar would look like, though.
Yeah, that makes sense.
As for what the grammar would look like, do you mean syntactically? It might flesh itself out if we can figure out how it might work. I assume you'd want to be able to define the structure of the text, and which parts of that structure translate into Dhall expressions. Maybe something like how bison/yacc work? Maybe it depends more on the expressive power of the grammar? I'm not really sure.