Skip to content
CCPEDIAby Unity Nodes
App Development

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

5 posts435 views8 likesLast activity Apr 2021

  1. Alexander_BernauerOP 3

    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

  2. cocreature 2

    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.

  3. Alexander_Bernauer 1

    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

  4. cocreature 1

    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.

  5. Luciano 1

    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.