Deriving Read

We can derive a Show instance in Daml, but is there a reason why we cannot derive Read that would do the inverse?


There are a few different reasons here:

  1. I would generally recommend to do input parsing & validation outside of Daml. Providing Read somewhat encourages doing the opposite and having generic Text inputs and parsing them in Daml.
  2. 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 while readMaybe is a thing, the default API throws on parse errors.
  3. 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.