Skip to content
CCPEDIAby Unity Nodes
App Development

Typeclass instances across packges and LF versions

2 posts101 views3 likesLast activity Jul 2026

  1. bernhardOP 1

    Splice defines a typeclass Splice.Amulet.TokenApiUtils.ToAnyValue with an instance

    instance ToAnyValue (ContractId t) where
      toAnyValue x = AV_ContractId $ coerceContractId x
    

    The Splice DARs are compiled to LF-2.1.

    When I now use that instance on a ContractId from the DA Registry (e.g. InstrumentConfiguration), which is compiled to LF-2.2, I get an error

    No instance for (ToAnyValue (ContractId t))
            arising from a use of ‘toAnyValue’
    

    This is reproducible using SDK 3.5.1 using the following daml.yaml and Main.daml:

    name: utils-tsv2-test-main
    source: daml
    version: 0.0.1
    dependencies:
      - daml-prim
      - daml-stdlib
    data-dependencies:
      - ../lib/splice-api-token-holding-v2-1.0.0.dar
      - ../lib/splice-api-token-metadata-v1-1.0.0.dar
      - ../lib/splice-api-token-transfer-instruction-v2-1.0.0.dar
      - ../lib/splice-token-standard-utils-2.0.0.dar
      - ../lib/utility-registry-app-v0-0.7.0.dar
      - ../lib/utility-registry-v0-0.6.0.dar
      - ../lib/splice-amulet-0.1.22.dar
    
    module Main where
    
    import Utility.Registry.V0.Configuration.Instrument
    import Splice.Amulet.TokenApiUtils (ToAnyValue(toAnyValue))
    import Splice.Api.Token.MetadataV1 (AnyValue(..))
    
    x : ContractId t -> AnyValue
    x y = toAnyValue y
    
    z : ContractId InstrumentConfiguration
    z = undefined
    
    a = x z
    

    However, I can add my own instance by copying and pasting from the Splice module. The following does compile just fine.

    module Main where
    
    import Utility.Registry.V0.Configuration.Instrument
    import Splice.Amulet.TokenApiUtils (ToAnyValue(toAnyValue))
    import Splice.Api.Token.MetadataV1 (AnyValue(..))
    
    instance ToAnyValue (ContractId t) where
      toAnyValue x = AV_ContractId $ coerceContractId x
    
    x : ContractId t -> AnyValue
    x y = toAnyValue y
    
    z : ContractId InstrumentConfiguration
    z = undefined
    
    a = x z
    

    Why is that? Is there any way to pull in the identical instance definition from Splice.Amulet.TokenApiUtils?

    As a note, I have no idea whether this has anything to do with LF versions, I just wanted to point out that there are two versions involved.

  2. Simon_Meier 2

    Not the answer you are looking for, but note that the module you are importing is an implementation module of splice-amulet and should be considered private. It is not meant to be used outside of splice implementation packages. If Daml had a way to mark these modules as private I would have marked them as private.

    So your option of redefining the class is actually the recommended way in this case.

    That said: I am interested as to why the import is failing at the technical level, as there can be cases where such an import is done for non-private functions.