Question regarding daml `Ambiguous occurrence` error
- cohen.avrahamOP
G-d willing
I have a question about how
damlinterprate function names and data types.
The situation goes as follows, let’s say I have a file nameUse.damland i declare in it the following function:firstValue : Int firstValue = 5later at that file I want to use this
firstValuesuch as:let myValue = firstValueUp 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 : IntSo, now, when I import this
DataType.damlintoUse.damlI am getting an error on theletcommand, sayingAmbiguous occurrenceand I don’t understand why.
I would understand it if in theDataType.damlfile I will have another function with the same name.Can someone please help me understand the reason for this?
- Gary_Verhaegen
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
firstValuein scope.The solution here is qualified imports, which I’ve explained in more details in the past.
- cohen.avraham
Thanks @Gary_Verhaegen,
I am aware of the imports as qualified, however, how can I specify to use my local functionfirstValueand not the one from the import? - Gary_Verhaegen 3
When you
importa library without thequalifiedkeyword, 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