We can derive a Show
instance in Daml, but is there a reason why we cannot derive Read
that would do the inverse?
2 Likes
There are a few different reasons here:
- I would generally recommend to do input parsing & validation outside of Daml. Providing
Read
somewhat encourages doing the opposite and having genericText
inputs and parsing them in Daml. - Even in Haskell
Read
is generally something you use for debugging not something you use in a production program. It’s inefficient, doesn’t provide any flexibility wtr to how you seralize and whilereadMaybe
is a thing, the default API throws on parse errors. - Because Daml has a proper
Text
type rather than building on a list of characters, we need some adjustments to make what GHC provides work. And it also generally ends up being very inefficient because making something efficient on a list of characters is different from making it efficient on a proper Text type (and Daml has more or less no optimizer).Show
suffers from different performance problems.
I think none of those are deal breakers and if demand for this increases, I think we could reconsider it.
3 Likes