Typeclass instances across packges and LF versions
App Development1 posts42 views1 likesLast activity 5d ago
BE
bernhardOP
5d agoSplice 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.