-
Notifications
You must be signed in to change notification settings - Fork 3
Use within Haskell ? #8
Comments
@checkraiser: See this line which is the key step: Line 59 in baa3358
The I'm planning on moving off of IPFS onto GitHub (See: dhall-lang/dhall-lang#162) but I'll also try to redeploy the IPFS mirror for the Dhall prelude as soon as I can. |
@Gabriel439 How about separating |
@checkraiser: Can you clarify what you mean by |
@Gabriel439 Sorry for delaying. |
@checkraiser: You can load some Dhall functions into Haskell, with some restrictions:
Here is an example. Suppose that you have the following Dhall function to template HTML: -- example.dhall
λ(greeting : Text)
→ λ(name : Text)
→ ''
<html>
<body>
${greeting}, ${name}!
</body>
</html>
'' Then you can load that function into Haskell and use it to template the HTML with different values:
You can also pass Haskell data types to the function that you use to template the HTML. The above trick works for any function argument that implements the For example, suppose that we change our Dhall code to: -- example.dhall
λ(record : { greeting : Text, name : Text })
→ ''
<html>
<body>
${record.greeting}, ${record.name}!
</body>
</html>
'' You can supply a Haskell record as an input to that function like this: {-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedStrings #-}
import Data.Text (Text)
import Dhall (Generic, Inject)
import qualified Data.Text.IO
import qualified Dhall
data Record = Record { greeting :: Text, name :: Text }
deriving (Generic, Inject)
main :: IO ()
main = do
function <- Dhall.input Dhall.auto "./example.dhall"
Data.Text.IO.putStr (function (Record { greeting = "Hello", name = "John" })) |
How to use library within Haskell as a html or json templating engine ?
Note: I can't access
ipfs
functions, the host takes to long to respond.The text was updated successfully, but these errors were encountered: