Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upProvide a pure version of `input` #87
Comments
This comment has been minimized.
This comment has been minimized.
|
The next release of ... so you will have access to a new extract :: Type a -> Expr X X -> Maybe a... and if you apply that to extract auto :: Interpret a => Expr X X -> Maybe a... which gives you a pure extraction function. Would that satisfy your use case? |
This comment has been minimized.
This comment has been minimized.
|
That sounds great indeed! What if my dhall script is a function, lets say |
This comment has been minimized.
This comment has been minimized.
|
Assuming that you have a Dhall function of type myDhallFunction :: Expr X XYou can turn that into a Haskell function of type myHaskellFunction :: Text -> Text
myHaskellFunction input = case extract auto (App myDhallFunction (TextLit input)) of
Just input -> input
Nothing -> error "This shouldn't happen if the function type-checks"I can add an interpret instance that does this for a limited subset of functions but it will take some time because it requires adding a new class, so I would recommend use the above approach for now |
This comment has been minimized.
This comment has been minimized.
|
Sorry, one correction. It should be: myHaskellFunction :: Text -> Text
myHaskellFunction input = case extract auto (normalize (App myDhallFunction (TextLit input))) of
Just input -> input
Nothing -> error "This shouldn't happen if the function type-checks" |
This comment has been minimized.
This comment has been minimized.
|
Here's a first draft of what I have in mind: #88 It still needs more work though (to add tests, documentation, and generic programming support for user-defined types) |
This comment has been minimized.
This comment has been minimized.
|
Thanks a lot @Gabriel439! I need some time to process that, as I am not very familiar with the |
This comment has been minimized.
This comment has been minimized.
|
The tutorial doesn't explain how to use this yet, but here's an example: >>> :set -XOverloadedStrings
>>> f <- input auto "λ(x : Text) → λ(y : Text) → x ++ y" :: IO (Text -> Text -> Text)
>>> f "ABC" "DEF"
"ABCDEF" |
This comment has been minimized.
This comment has been minimized.
|
This is awesome! Thank you very much, that is exactly what I need. |
This comment has been minimized.
This comment has been minimized.
|
Fixed by #88 |
Gabriel439
closed this
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks for the impressive reactivity. Do you plan to release a new version any time soon? |
This comment has been minimized.
This comment has been minimized.
|
Yes. I will probably publish a new version within about a week |
This comment has been minimized.
This comment has been minimized.
|
This is now up on Hackage as |
lthms commentedJul 20, 2017
Hi! I am currently working on a project whichin I would love to use dhall to improve its customization power. However, in order to do so without breaking too many things, I was wondering if it would be possible to use dhall script in pure functions.
That is, I would love to be able to load and parse the script once, then run it in a pure way several time with different arguments.
Do you think it is possible?