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

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

Maybe something like this?

> setup@ProductSetup { .. } <- partySetup >>= productSetup
> setup.productId
1 Like

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

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

1 Like

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

1 Like

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


$ 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"
1 Like

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

1 Like

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

1 Like

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.

1 Like