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
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.
3 Likes