Return type of a Choice

sorry, I"m trying to fast track myself thru DAML , by asking what may be silly questions a few more hours of study would have figured out.

in the docs example they show this:

ContractId User

which seems strange i.e. I would have figured a return type would be a a class I had defined or was previously defined by the SDK , yet this looks like some sort fo composite return type demarcated by a space.

So I guess the first question is what entities which I assume would be defined in DAML constitute something that can be used as the return type for a Choice which I think of as an operation.

And what is the significance above of what seems to be a composite return type.

Finally, thanks for indulging me, I’m just swamped and need to get my head around DAML or stick to what I know most i.e. Corda.

thanks

For a deep dive on datatypes in Daml I recommend the corresponding section in the daml intro.

For this specific example, ContractId is a type which takes one type parameter corresponding to the template type it points to. ContractId User is then a “pointer” to a User contract which you can “dereference” with fetch. If you’re familiar with Corda and thereby also Kotlin, this is like generics in Kotlin. The syntax is just slightly different so instead of ContractId<User>, Daml uses ContractId User slightly similar to how function application is f x instead of f(x).

As for the general question on which types can be used as the return type of a choice, the answer is anything that is serializable. You can find a formal definition of serializability in the LF spec but as a rule of thumb anything that can be compared and easily serialized to text or binary format is serializable so things like strings, ints, anything that is composed of those but not functions or anything that contains functions.

1 Like

much thanks, that all makes a lot of sense

1 Like

References to contracts have the type ContractId a , where a is a type parameter representing the type of contract that the ID refers to. For example, a reference to a Token would be a ContractId Token .

1 Like