Is the `ApplicativeDo` language pragma implicitly enabled in Daml? Update: no, it isn't

The Daml docs says about the Commands data type:

“This is used to build up the commands sent as part of submit. If you enable the ApplicativeDo extension by adding {-# LANGUAGE ApplicativeDo #-} at the top of your file, you can use do-notation but the individual commands must not depend on each other and the last statement in a do block must be of the form return expr or pure expr.”

See Module Daml.Script — Daml SDK 1.10.0 documentation

Is my observation correct that enabling this pragma is not needed any more?

1 Like

The pragma is still needed but you only need it if you actually make use of do notation. E.g., the following works without the pragma because the do is redundant.

submit p $ do createCmd …

This one does not:

submit p $ do
  c1 <- createCmd …
  c2 <- createCmd
  pure (c1, c2)
2 Likes

Thank you!

1 Like

Further to what @cocreature said, it is only needed for dos associated with Commands. Script (the Action that submit produces in this context) can use do without the pragma.

If you need this pragma and haven’t added it, compilation will fail. Conversely, if you don’t have it and your code is compiling, you don’t need it.

4 Likes

Thank you!

1 Like