Can I apply type constraints to a function signature which is a record field type?
I understand what type constraints are and how we can use them, e.g. from this guide written by @Stephen.
Now I’m trying to apply a type constraint to a function signature which is a record field type, and get the following error:

Am I doing something wrong, or this is not allowed in Daml?
There are two likely possibilities:
- You want
given,when, andthen_to be polymorphic overmeven given a singleTest'value. Your declaration means that eachTest'serves exactly onem; if that is not what you mean, removemfromTest''s type parameters, and typegiven : forall m. (CanAbort m) => m aand likewise for the other functions. (Because this is a more exotic form of type polymorphism, Daml can’t figure out where themshould be inferred otherwise.) - You want
mto be fixed to a particularmfor eachTest'. In that case, there is no benefit to putting the constraints in the record structure; typeclass coherence means that if you satisfy the constraint when creating theTest', it will give exactly the same solution to the constraint as if you satisfied it when extracting and using one of the functions. So you might as well move theCanAbort mconstraint to whatever function producesTest'values.
One other note: for this forum, it is preferred that you paste code and error messages as text in blocks as explained here, rather than screenshots. That way, for example, I could simply copy-and-paste your sample code and edit it; not a big deal here but definitely important for bigger samples.
Thank you, @Stephen for the answer, #2 works perfectly, and also the reminder to avoid screen shots, I will follow this guidance. (It’s tempting to insert a screen shot because it displays the error message, while the copy+pasted code doesn’t. )
It’s tempting to insert a screen shot because it displays the error message, while the copy+pasted code doesn’t.
I think this used to not work in VS Code, but as of Code 1.67.2 at least, you can move the mouse into the error tooltip, select text, and copy with Ctrl-C/Cmd-C. I highly recommend this for sharing errors from Code.
Thanks, will use this.
