Iterating over a list with `createCmd` in a script
- georgOP 1
I often write the following, intuitively thinking that it should work:
forA_ list $ submit party do createCmdThis throws the error:
Couldn't match type ‘Commands (ContractId t0)’ with ‘Script b0’ Expected type: MyListTemplate -> Script b0 Actual type: MyListTemplate -> Commands (ContractId t0)I’ve meanwhile found out what it should be, and I think I understood why that is:
submit party do forA_ list createCmdBut could someone ELI5 (explain like I’m 5) why the former approach doesn’t work?
EDIT:
I suppose the confusing thing is that this actually does work:forA_ list (\c -> submit party do createCmd c)So why is
submit party do createCmdnot the same as\c -> submit party do createCmd cin this case? - cocreature 2
forA_ list $ submit party . createCmdshould also work. Your example is equivalent toforA_ list $ \c -> ((submit party) createCmd) cwhich leads to the type error you are seeing:
submithas typeParty -> Commands a -> Script abut the second argument you are applying it to iscreateCmdnotcreateCmd cwhich has the wrong type.submit party $ do forA_ list createCmdhas different semantics. It creates all contracts in a single transaction rather than spread out over multiple transactions. - georg
Great answer, and truly ELI5
thanks!