# To abort or to fail

**URL:** <https://forum.canton.network/t/to-abort-or-to-fail/3012>\
**Category:** App Development\
**Created:** [August 18, 2021, 7:06pm UTC](https://forum.canton.network/t/to-abort-or-to-fail/3012 "2021-08-18T19:06:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [August 18, 2021, 7:06pm UTC](https://forum.canton.network/t/to-abort-or-to-fail/3012/1 "2021-08-18T19:06:47Z")

</div>

Within the Prelude we define [CanAbort](https://docs.daml.com/daml/stdlib/Prelude.html#class-da-internal-lf-canabort-20311) and [ActionFail](https://docs.daml.com/daml/stdlib/Prelude.html#class-da-internal-prelude-actionfail-8575) typeclasses with similar definitions. When should we use one versus the other?

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [August 24, 2021, 10:32am UTC](https://forum.canton.network/t/to-abort-or-to-fail/3012/2 "2021-08-24T10:32:10Z")

</div>

`ActionFail` exists to desugar pattern matches in do-notation desugar and not really anything else, e.g.,

```haskell
Some x <- y

```

I woulnd’t really recommend writing anything that is polymorphic in `ActionFail` or calling `fail` yourself.

`CanAbort` on the other hand is intended for user-defined code and the standard library and so on.  
Writing code polymorphic in that is perfectly reasonable.

So while the two are equivalent on the technical level they differ in how they are and are intended to be used.

---

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [August 24, 2021, 2:22pm UTC](https://forum.canton.network/t/to-abort-or-to-fail/3012/3 "2021-08-24T14:22:13Z")

</div>

Thank you. Would you be opposed if I added this information to the docs?

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [August 24, 2021, 2:22pm UTC](https://forum.canton.network/t/to-abort-or-to-fail/3012/4 "2021-08-24T14:22:29Z")

</div>

Not at all, that would be great!

---

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [September 4, 2021, 8:52pm UTC](https://forum.canton.network/t/to-abort-or-to-fail/3012/5 "2021-09-04T20:52:02Z")

</div>

To follow up a bit on this thread, does this mean that ideally the `Total` modules in the DA stdlib (ex. [DA.List.Total](https://docs.daml.com/daml/stdlib/DA-List-Total.html)) should have used `CanAbort` instead?

What’s also the right verb here? Does a function “use” a typeclass or “implement” it?

---

<div class="post-metadata">

**Author:** ![akrmn](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/akrmn/32/2484_2.png) [@akrmn](https://forum.canton.network/u/akrmn)\
**Post date:** [September 14, 2021, 7:52am UTC](https://forum.canton.network/t/to-abort-or-to-fail/3012/6 "2021-09-14T07:52:34Z")

</div>

That’s an interesting question @Leonid_Rozenberg. Looking at the code in [DA.List.Total](https://github.com/digital-asset/daml/blob/053f22a1afa99cbd154bf900e99ed3b95280a884/compiler/damlc/daml-stdlib-src/DA/List/Total.daml), it seems like these functions all use `fail` to report pattern match failures, so to me `ActionFail` is appropriate. I think that still agrees with @cocreature’s recommendation against “writing anything that is polymorphic in `ActionFail` or calling `fail` yourself” since this isn’t “yourself” writing these functions.

Regarding your other question, I’d say “use” (I did above!). I’d reserve “implement” for `instance`s, e.g. `map` is the implementation of `fmap` for `[]`.

---

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [September 14, 2021, 12:20pm UTC](https://forum.canton.network/t/to-abort-or-to-fail/3012/7 "2021-09-14T12:20:48Z")

</div>

I see. My point though is that the fact that they use `fail` is an implementation detail. For the purposes of programming with them it would be easier if their signature had `CanAbort` instead as I would want to use that typeclass in my potentially-failing code.

---

<div class="post-metadata">

**Author:** ![akrmn](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/akrmn/32/2484_2.png) [@akrmn](https://forum.canton.network/u/akrmn)\
**Post date:** [September 14, 2021, 2:59pm UTC](https://forum.canton.network/t/to-abort-or-to-fail/3012/8 "2021-09-14T14:59:43Z")

</div>

That’s a good point, any `Action`-polymorphic code using these is going to inherit the `ActionFail` constraint. With that argument, I agree that `CanAbort` would be more appropriate. What do you think @cocreature?
