G-d willing
I have a question about how daml
interprate function names and data types.
The situation goes as follows, let’s say I have a file name Use.daml
and i declare in it the following function:
firstValue : Int
firstValue = 5
later at that file I want to use this firstValue
such as:
let myValue = firstValue
Up to this point, everything is okay and works normally. However, now I decide to add another file named DataType.daml
. In this file I declare the following data type:
data SomeDataType = SomeDataType with
firstValue : Int
So, now, when I import this DataType.daml
into Use.daml
I am getting an error on the let
command, saying Ambiguous occurrence
and I don’t understand why.
I would understand it if in the DataType.daml
file I will have another function with the same name.
Can someone please help me understand the reason for this?
Without going too much into the underlying details, the simple explanation is that data type fields are, in Daml, functions. So you really do have two functions called firstValue
in scope.
The solution here is qualified imports, which I’ve explained in more details in the past.
Thanks @Gary_Verhaegen,
I am aware of the imports as qualified, however, how can I specify to use my local function firstValue
and not the one from the import?
When you import
a library without the qualified
keyword, you get its exported names (default: all) both as qualified and unqualified. The same is true of the current module. Here’s a short example.
Lib.daml
module Lib where
one : Int
one = 1
ambiguous : Text
ambiguous = "Lib"
Main.daml
module Main where
import Daml.Script
import Lib
ambiguous : Text
ambiguous = "Main"
setup : Script ()
setup = script do
debug $ one
debug $ Main.ambiguous -- using the name of the current module
3 Likes