我怎样才能 print/encode 一个值到 Dhall?
How can I print/encode a value into Dhall?
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
import Dhall
data Example = Example { foo :: Natural, bar :: Vector Double }
deriving (Generic, Show)
instance Interpret Example
main :: IO ()
main = do
putStrLn "Hello, Haskell!"
x <- input auto "./example.dhall"
print (x :: Example)
在上面的示例中,我如何才能将 Example
编码为 dhall 值,因此本质上是 Example -> String
类型的函数?似乎无法在黑线鳕中找到任何关于打印/编码的参考。
这就是您如何 pretty-print 一个 Haskell 值作为等效的 Dhall 表达式:
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedStrings #-}
import Dhall (FromDhall, Natural, ToDhall, Vector)
import Dhall.Pretty (CharacterSet(..))
import GHC.Generics (Generic)
import qualified Data.Text.Prettyprint.Doc.Render.Text as Prettyprint.Text
import qualified Dhall
import qualified Dhall.Pretty
import qualified Dhall.Core
data Example = Example { foo :: Natural, bar :: Vector Double }
deriving (FromDhall, Generic, Show, ToDhall)
main :: IO ()
main = do
x <- Dhall.input Dhall.auto "./example.dhall"
let expression = Dhall.embed Dhall.inject (x :: Example)
let doc = Dhall.Pretty.prettyCharacterSet Unicode expression
Prettyprint.Text.putDoc doc
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
import Dhall
data Example = Example { foo :: Natural, bar :: Vector Double }
deriving (Generic, Show)
instance Interpret Example
main :: IO ()
main = do
putStrLn "Hello, Haskell!"
x <- input auto "./example.dhall"
print (x :: Example)
在上面的示例中,我如何才能将 Example
编码为 dhall 值,因此本质上是 Example -> String
类型的函数?似乎无法在黑线鳕中找到任何关于打印/编码的参考。
这就是您如何 pretty-print 一个 Haskell 值作为等效的 Dhall 表达式:
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedStrings #-}
import Dhall (FromDhall, Natural, ToDhall, Vector)
import Dhall.Pretty (CharacterSet(..))
import GHC.Generics (Generic)
import qualified Data.Text.Prettyprint.Doc.Render.Text as Prettyprint.Text
import qualified Dhall
import qualified Dhall.Pretty
import qualified Dhall.Core
data Example = Example { foo :: Natural, bar :: Vector Double }
deriving (FromDhall, Generic, Show, ToDhall)
main :: IO ()
main = do
x <- Dhall.input Dhall.auto "./example.dhall"
let expression = Dhall.embed Dhall.inject (x :: Example)
let doc = Dhall.Pretty.prettyCharacterSet Unicode expression
Prettyprint.Text.putDoc doc