Tell me why this isn't a good idea. I'm thinking that dhall might be really suitable as a templating language ala mustache, but with types:
let Person =
{ name : Text
, age : Natural
}
let Message =
{ recipient : Person
, sender : Person
, content : Text
}
let Text/concatMapSep = https://prelude.dhall-lang.org/Text/concatMapSep sha256:c272aca80a607bc5963d1fcb38819e7e0d3e72ac4d02b1183b1afb6a91340840
let renderMessage : Message -> Text =
\(message : Message) ->
''
Message from ${message.sender.name}
Sent to ${message.recipient.name}
${message.content}
''
let fun : List Message -> Text =
Text/concatMapSep "----------------------" Message renderMessage
in
fun
{-# LANGUAGE DerivingVia #-}{-# LANGUAGE DataKinds #-}{-# LANGUAGE DeriveGeneric #-}{-# LANGUAGE TypeOperators #-}moduleMainwhereimportDhall.DerivingimportGHC.Generics(Generic)importDhall(FromDhall(..),ToDhall(..),inputFile,auto)importData.Text(Text)importqualifiedData.Text.IOasTimportNumeric.NaturaldataPerson=Person{personName::!Text,personAge::!Natural}deriving(Show,Generic)deriving(FromDhall,ToDhall)viaCodec(Field(CamelCase<<<DropPrefix"person"))PersondataMessage=Message{messageRecipient::!Person,messageSender::!Person,messageContent::!Text}deriving(Show,Generic)deriving(FromDhall,ToDhall)viaCodec(Field(CamelCase<<<DropPrefix"message"))Messagemain::IO()main=dorenderMessage<-inputFileauto"template.dhall"letrecipient=Person"foo"3sender=Person"bar"3T.putStrLn.renderMessage$[Messagerecipientsender"content of the message"]
This is using the a -> b instance of FromDhall to "compile" the templates, so you end up having a normal [Message] -> Text as your template function in haskell, so there is no round tripping to dhall.
I think that's a great idea, as long as you can define the input using dhall types. I have been doing such things using the cli, e:g: dhall text <<< "./template.dhall $(yaml-to-dhall input.yaml)"
One of the downsides I can think of is the lack of date types and their formatters. You end up normalizing the records to text and whatever else primitives
Tell me why this isn't a good idea. I'm thinking that dhall might be really suitable as a templating language ala mustache, but with types:
This is using the
a -> b
instance ofFromDhall
to "compile" the templates, so you end up having a normal[Message] -> Text
as your template function in haskell, so there is no round tripping to dhall.I think that's a great idea, as long as you can define the input using dhall types. I have been doing such things using the cli, e:g:
dhall text <<< "./template.dhall $(yaml-to-dhall input.yaml)"
One of the downsides I can think of is the lack of date types and their formatters. You end up normalizing the records to text and whatever else primitives