Skip to content
Discussions/App Development/Turning a compile-time symbol into a run-time TextForum ↗

Turning a compile-time symbol into a run-time Text

App Development5 posts394 views8 likesLast activity Apr 2021
AL
Alexander_BernauerOP
Feb 2021

Hi

as a follow-up to (1) I was wondering, how can I get a runtime string from a compile time symbol such as @"bar". I need this for error reporting in cases where the field is an Optional and happens to be None.

In Haskell I believe the answer is symbolVal. But I am not allowed to import GHC.TypeLits. What is the DAML way of doing this?

CC: @Sofia_Faro, maybe you know?

Regards,
Alex

(1) Generating record update functions to be used as parameters - #3 by Sofia_Faro

CO
cocreature
Feb 2021

At the moment, you can’t. We don’t provide symbolVal in Daml. You can define your own typeclass that has a symbolVal instance but you’ll have to write instances for every string you need.

AL
Alexander_Bernauer
Feb 2021

Hi @cocreature,

it seems this is not possible either, because I cannot import GHC.Types, this being considered an internal module. Here is what I am trying to do

 class FieldName (x : Symbol) where
    fieldName : Text

Is there another way to implement your proposal that avoids using Symbol? Or is there a way to import internal packages after all?

Regards,
Alex

CO
cocreature
Feb 2021

That’s a good point. I don’t think there is a good solution here atm unfortunately. We deliberately kept Symbol hidden since it can cause problems in cross-SDK dependencies so circumventing the import restriction isn’t going to help either.

LU
Luciano
Apr 2021

I know this won’t answer your question directly, but have you looked at DA.Stack? It provides some introspection ability, and although you won’t be able to access the AST, at least you can get information about the file/line numbers when debugging. It got snuck in to the SDK, not quite sure when.

← Back to Discussions