Search code examples
daml

What is the '$' operator?


I come across some examples in the Daml documentation where the operator '$' is being used, but cannot fully understand its purpose.

Example:

submit alice $ create User with username = alice, following = []

Is it the same as do, like in:

submit alice do
  create User with username = alice, following = []

?


Solution

  • The $ operator is a substitute for parenthesis. The example

    submit alice $ create User with username = alice, following = []
    

    is the same as

    submit alice (create User with username = alice, following = [])
    

    To complete, the do is used to declare a code block (more than one line of code):

    test = scenario do
      alice <- getParty "Alice"
      bob <- getParty "Bob"
      ...
    

    However, it can also be used in a single line of code:

    submit alice do create User with username = alice, following = []