summaryrefslogtreecommitdiff
path: root/templates/encode.hs.ede
blob: f305eb14df557a31c9214786f8f6660f17a34689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- generated file, do not modify!
-- {{ dateTime }}

{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
module {{ moduleName }}Encode where

import Data.Text
import Data.Aeson hiding (Value,Bool)
import Data.Aeson.Types hiding (Value,Bool)
import Linear

import {{ moduleName }}

(.-) :: Text -> Text -> Pair
a .- b = a .= b

{% for t in definitions %}
instance ToJSON {{ t.value.dataName }} where
  toJSON v = case v of{% for c in t.value.constructors %}{% if c.value.fields | hasFieldNames %}
    {{ c.value.name }}{..} -> object
      [ "tag" .- "{{ c.value.name }}"{% for f in c.value.fields %}
      , "{{ f.value.fieldName }}" .= {{ f.value.fieldName }}{% endfor %}
      ]{% else %}
    {{ c.value.name }}{% for f in c.value.fields %} arg{{ f.index0 }}{% endfor %} -> object [ "tag" .- "{{ c.value.name }}"{% for f in c.value.fields %}, "arg{{ f.index0 }}" .= arg{{ f.index0 }}{% endfor %}]{% endif %}{% endfor %}

{% endfor %}