Deriving Read
App Development2 posts610 views5 likesLast activity Jun 2021
LE
Leonid_RozenbergOP
Jun 2021We can derive a Show instance in Daml, but is there a reason why we cannot derive Read that would do the inverse?
CO
cocreature
Jun 2021There are a few different reasons here:
- I would generally recommend to do input parsing & validation outside of Daml. Providing
Readsomewhat encourages doing the opposite and having genericTextinputs and parsing them in Daml. - Even in Haskell
Readis 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 whilereadMaybeis a thing, the default API throws on parse errors. - Because Daml has a proper
Texttype 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).Showsuffers from different performance problems.
I think none of those are deal breakers and if demand for this increases, I think we could reconsider it.