Could you link any simple examples on calculating a type or TypeRep based on incoming JSON data?
One of my bigger interests in Haskell right now is the Frames library but I've honestly been struggling with using and understanding Template Haskell to generate Types.
I haven't had a ton of time so it isn't all TH's fault either. I've also read the Template Haskell paper and the entire system seems well thought out, I suppose there just aren't enough practical tutorials I can mess about with until I understand.
(Not the OP) I don't know of any examples of using JSON to create types, but here [0] is a practical example of creating types dynamically from input, via writing a type-safe printf:
My most recent hack in this area is in [1]. We read in a bunch of type signatures from JSON and parse them with haskell-src-exts, but Haskell doesn't give us a way to turn these representations-of-types into actual types. The values we're constructing are to be passed into an API which requires all of its arguments to be Typeable, which it hides inside several layers of existentials (heterogeneous lists of heterogeneous maps of ...).
Thankfully for our purposes there's an escape hatch: the values we provide won't be evaluated, so they can be `undefined`, and the `TypeRep`s generated from these values are only used for determining whether two types are (intensionally) equal or different.
My solution was to define two new types, `Z` and `S a`, which can be used as peano numerals. We convert all of the distinct types in our JSON into distinct peano numeral types (`replaceTypes`), we generate `TypeRep` values for these numeral types (`getRep`), fabricate values of these types as arguments to the underlying library (`getVal`), then switch back all of the types which occur in the result (`restoreTypes`).
Very ugly, but it works, thanks to the wiggle room I had based on what these types and values would be used for.
Other projects have been even more icky, e.g. sending strings of auto-generated Haskell code through `runhaskell` [2] and throwing auto-generated template haskell into GHCi to see what sticks [3].
I don't recommend any of this for production code :)
One of my bigger interests in Haskell right now is the Frames library but I've honestly been struggling with using and understanding Template Haskell to generate Types.
I haven't had a ton of time so it isn't all TH's fault either. I've also read the Template Haskell paper and the entire system seems well thought out, I suppose there just aren't enough practical tutorials I can mess about with until I understand.