Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Provide a pure version of `input` #87
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?
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?
That sounds great indeed! What if my dhall script is a function, lets say
Assuming that you have a Dhall function of type
myDhallFunction :: Expr X X
You 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
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"