# What is the diff between pure() and return() ?Could you give me an example?

**URL:** <https://forum.canton.network/t/what-is-the-diff-between-pure-and-return-could-you-give-me-an-example/978>\
**Category:** App Development\
**Tags:** daml\
**Created:** [August 4, 2020, 7:58am UTC](https://forum.canton.network/t/what-is-the-diff-between-pure-and-return-could-you-give-me-an-example/978 "2020-08-04T07:58:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![huixin\_liu](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/huixin_liu/32/689_2.png) [@huixin\_liu](https://forum.canton.network/u/huixin_liu)\
**Post date:** [August 4, 2020, 7:58am UTC](https://forum.canton.network/t/what-is-the-diff-between-pure-and-return-could-you-give-me-an-example/978/1 "2020-08-04T07:58:24Z")

</div>

I defined template ,when i want to get nothing , i would use pure() or return() .But i could not find the diff between pure() and return()

---

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [August 4, 2020, 8:08am UTC](https://forum.canton.network/t/what-is-the-diff-between-pure-and-return-could-you-give-me-an-example/978/2 "2020-08-04T08:08:28Z")

</div>

In the context that you are seeing these two statements inside a `do` block (i.e. when writing a `Choice` for example), they probably mean the same thing.

~~`pure` is a function that is defined in `Applicative` typeclass, whereas `return` is defined in the `Action` typeclass (aka `Monad`), which is a ‘subclass’ of the former, if you like. I believe that the implementation of `return` is just `return = pure`.~~

 

~~The only difference, as a developer, when looking at code outside the `do` notation, is that if you see `return` , you can assume that you can use monadic `>>=` in addition to `<*>` and `liftA2` from `Applicative`. The converse is _not_ true.~~

\*\*edit: Please see @cocreature’s post below \*\*

---

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [August 4, 2020, 8:15am UTC](https://forum.canton.network/t/what-is-the-diff-between-pure-and-return-could-you-give-me-an-example/978/3 "2020-08-04T08:15:42Z")

</div>

I also recommend you look at the recent tutorial [If you are not 100% sure about `do` blocks, `\<-` notation and `return`, you should read this](https://discuss.daml.com/t/if-you-are-not-100-sure-about-do-blocks-notation-and-return-you-should-read-this/968), which explains the relationship between `do` notation and `Action`.

I think that `return` was added originally just as syntactic sugar, so you could have a `do ... return` statement. I recall that in Haskell there also exists an applicative `do` extension, but I don’t think we have this in DAML.

---

<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 4, 2020, 8:43am UTC](https://forum.canton.network/t/what-is-the-diff-between-pure-and-return-could-you-give-me-an-example/978/4 "2020-08-04T08:43:39Z")

</div>

In DAML they are literally equivalent. `return` is part of `Action` in Haskell but in DAML, it is simply a synonym for `pure`.

---

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [August 4, 2020, 8:52am UTC](https://forum.canton.network/t/what-is-the-diff-between-pure-and-return-could-you-give-me-an-example/978/5 "2020-08-04T08:52:15Z")

</div>

This is … surprising. Do you know if there’s some reason behind this?

---

<div class="post-metadata">

**Author:** ![SamirTalwar](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/samirtalwar/32/374_2.png) [@SamirTalwar](https://forum.canton.network/u/SamirTalwar)\
**Post date:** [August 4, 2020, 9:39am UTC](https://forum.canton.network/t/what-is-the-diff-between-pure-and-return-could-you-give-me-an-example/978/6 "2020-08-04T09:39:39Z")

</div>

Many people consider the separation between `pure` and `return` in Haskell to be a mistake. From what I recall, it’s because `Monad` wasn’t defined in terms of `Applicative` when it first showed up, so it needed its own function to lift a value.

In GHC 7.10, [this heirarchy was fixed](https://wiki.haskell.org/Functor-Applicative-Monad_Proposal), making `return` redundant. However, there are plenty of cases where `return` and `pure` don’t do exactly the same thing, or where `return` was defined regardless, so it couldn’t just be removed.

There are plans to stop people overriding `return` (and `>>`) in the [monad of no return](https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return) proposal, but I believe it’s going to be a while.

DAML doesn’t have this historical baggage, so doesn’t need `return` in the `Action` typeclass. It can be defined outside. I don’t know the history, but I’m assuming it wasn’t made overridable because there’s no way to make it do something different from `pure` without breaching the laws.

---

<div class="post-metadata">

**Author:** ![sofusmortensen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/sofusmortensen/32/791_2.png) [@sofusmortensen](https://forum.canton.network/u/sofusmortensen)\
**Post date:** [October 5, 2020, 10:42am UTC](https://forum.canton.network/t/what-is-the-diff-between-pure-and-return-could-you-give-me-an-example/978/7 "2020-10-05T10:42:58Z")

</div>

`return` is an alias to `pure`.

Learning DAML, as a domain expert but not FP developer, `return` is arguably easier to grasp.

`pure` has a strong smell of Haskell, which like the [durian fruit](https://en.wikipedia.org/wiki/Durian) is an acquired taste (at first it smells/tastes pretty bad, later you just can’t get enough).

Today, I prefer `pure`.

---

<div class="post-metadata">

**Author:** ![huixin\_liu](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/huixin_liu/32/689_2.png) [@huixin\_liu](https://forum.canton.network/u/huixin_liu)\
**Post date:** [December 17, 2020, 4:16am UTC](https://forum.canton.network/t/what-is-the-diff-between-pure-and-return-could-you-give-me-an-example/978/8 "2020-12-17T04:16:23Z")

</div>

> [@sofusmortensen](#):
>
> `return` is an alias to `pure` .
> 
> Learning DAML, as a domain expert but not FP developer, `return` is arguably easier to grasp.
> 
> `pure` has a strong smell of Haskell, which like the [durian fruit](https://en.wikipedia.org/wiki/Durian) is an acquired taste (at first it smells/tastes pretty bad, later you just can’t get enough).
> 
> Today, I prefer `pure` .

Thanks for your explaining.Very interesting 👏
