Skip to content
Discussions/App Development/How can I print out the value of local variables in REPL?Forum ↗

How can I print out the value of local variables in REPL?

App Development10 posts309 views7 likesLast activity Nov 2021
GY
gyorgybalazsiOP
Nov 2021

I’m running a script like this in REPL:

ProductSetup { .. } <- partySetup >>= productSetup

The ProductSetup record has a productId field, so the call binds a value to the local productId variable via record destructuring.

When I try to print out the value of productId, I get an Ambiguous occurrence ‘productId’ error, because this name is also contained in some imported packages.

Is there a way to namespace local variables in REPL? E.g. like this:

<module name of REPL>.productId
CO
cocreature
Nov 2021

Maybe something like this?

> setup@ProductSetup { .. } <- partySetup >>= productSetup
> setup.productId
GY
gyorgybalazsi
Nov 2021

Yeah, that’s an option, thanks. So no other means to namespace local variables?

CO
cocreature
Nov 2021

Right now no, you cannot reference the module you are in directly.

GA
Gary_Verhaegen
Nov 2021

You can namespace the external module, though, with import qualified MyModule as Prefix.

GY
gyorgybalazsi
Nov 2021
Gary_Verhaegen:

You can namespace the external module, though, with import qualified MyModule as Prefix

Can I do that when I import the module into REPL via command line?

GA
Gary_Verhaegen
Nov 2021

Sure:

$ daml new t
Created a new project in "t" based on the template "skeleton".
$ cd t
$ daml build
Compiling t to a DAR.
Created .daml/dist/t-0.0.1.dar
$ daml repl .daml/dist/t-0.0.1.dar
daml> import qualified Main as M
daml> let (Some alice) = partyFromText "alice"
daml> let (Some bob) = partyFromText "bob"
daml> let my_payload = M.Asset alice bob "some description"
daml>
CO
cocreature
Nov 2021

I think @gyorgybalazsi is referring to the --import flag of Daml Repl. You don’t get a choice to import those modules qualified unfortunately.

GA
Gary_Verhaegen
Nov 2021

Is there any advantage to using --import over calling import explicitly in the repl itself?

CO
cocreature
Nov 2021

The --import flag imports all modules from a package at once which can be very convenient in some cases. In the REPL you have to import modules one by one.

← Back to Discussions