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
Q: Can type of InjectWith / InputType be generalized? #819
Comments
Sorry for the delayed response on this So I'm not sure if we should reuse the Also, this doesn't necessarily require using wrap :: (Interpret input, Inject output) => (input -> output) -> Expr s a -> Expr s a |
I’d love to have this feature as well. If we can call dhall functions from the interpreting language, we should also be able to do the other way around. Small elaboration of my use-case: I want to be able to have “opaque” data in my dhall code, where the interpretation/implementation is up to the interpreter, yet the dhall file still type-checks with the normal dhall tools (no custom extension of the normalizer necessary to interpret the dhall file). For example, imagine a window manager configuration, and the user should be able to add and subtract keys from the set, but the set itself is not defined in dhall: let KeyMap = { key : Text, command : Text }
in λ(KeySet : Type)
→ λ(defaultKeyMap : KeySet)
→ λ(addKeys : KeySet → List KeyMap → KeySet)
→ λ(removeKeys : KeySet → List Text → KeySet)
→ addKeys
(removeKeys defaultKeyMap [ "key1", "key2" ])
[ { key = "Meta-x", command = "emacsclient" } ]
: KeySet which type-checks and normalizes just fine in dhall and exposes some functions that the user can apply to the opaque data type. This way the Haskell implementation can decide how to represent the data structure and how to implement the interpreter for the small It nearly works, except I cannot pass Haskell functions to dhall right now, because the If it’s possible I’d like to pair on this, because I’m interested in how to implement such a feature. |
@Profpatsch: Basically, you would need to add a new constructor to the data Expr s a =
...
| HaskellFunction { inputType :: Expr s a, outputType :: Expr s a, function :: Expr s a -> Expr s a } ... and then fix all the type errors. Then I believe you'd be able to implement the However, even if you did have such an instance your example wouldn't work because you wouldn't be able to |
FWIW, I've experimented locally with a data InputType a b = InputType
{ embed :: a -> Dhall.Core.Expr Dhall.Parser.Src b
, declared :: Dhall.Core.Expr Dhall.Parser.Src b
} The context is that some symbolic 'imports' are present in the output, which are resolved differently depending on format - e.g., one format's happy to have actual imports, but another wants them inlined; both of those are just a Specifically the current default-factoring code in |
I solved that, by writing this module: https://github.com/openlab-aux/vuizvui/blob/master/pkgs/profpatsch/xmonad/DhallTypedInput.hs |
This is more a question than an issue. I was earlier looking at how to recover BB-encodings on the Haskell side. The general idea I had was to use
Expr Src Dynamic
which could hold functions inside the dynamic. Then the normalizer, when it encounters an application of Èmbed would unwrap the function from dynamic, interpret the argument value, apply the function and inject the result back.This has two (obvious) caveats. First being that the
InputType
has anX
where I'd want aDynamic
. Would it be acceptable to relax this?The other, is, of course that the argument subexpression might not have a suitable normal form by itself. Would this be solved by additional normalization before computing the 'special' application?
The text was updated successfully, but these errors were encountered: