Can I override the Show instance for a template?
App Development2 posts316 views6 likesLast activity Oct 2021
GE
georgOP
Oct 2021I want to define a custom Show instance for my template so that I can pass it directly to debug and get pretty-printed output. Is there a way to override the default Show implementation? If not, what would a sensible workaround be?
CO
cocreature
Oct 2021I don’t think you can override it at the moment. I’d also generally recommend against doing so. It’s very convenient if show produces a valid Daml expression or at least something very close to it.
What you can do instead is to define a function of type pretty : YourTemplate -> Text and then instead of debug use trace:
trace (pretty yourTemplate) (pure ())
If someone wants to add traceM : Action m => Text -> m () to make this a bit more convenient, I’ll gladly accept a PR.