# Check for null values returned from forA

**URL:** <https://forum.canton.network/t/check-for-null-values-returned-from-fora/2766>\
**Category:** App Development\
**Tags:** daml\
**Created:** [June 28, 2021, 3:15pm UTC](https://forum.canton.network/t/check-for-null-values-returned-from-fora/2766 "2021-06-28T15:15:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pris17](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/pris17/32/2078_2.png) [@Pris17](https://forum.canton.network/u/Pris17)\
**Post date:** [June 28, 2021, 3:15pm UTC](https://forum.canton.network/t/check-for-null-values-returned-from-fora/2766/1 "2021-06-28T15:15:05Z")

</div>

How can we check for null values in the below snippet?

```haskell
[data1, data2] <- forA parties (\p -> do return (abc))

```

data1 and data2 are of record datatype. I want to make sure that these record type data1 and data2 are not null.

How can I achieve this?

---

<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:** [June 28, 2021, 3:31pm UTC](https://forum.canton.network/t/check-for-null-values-returned-from-fora/2766/2 "2021-06-28T15:31:15Z")

</div>

Daml values do not have an implicit `null`. If you have something of type `a`, it can never be null. If a value can be absent this is encoded explicitly via `Optional a`. In that case, you can do the equivalent of a null-check via a pattern match, e.g.,

```haskell
case data1 of
  None -> _ -- "do something here"
  Some d -> _ -- "do something here with d"

```

---

<div class="post-metadata">

**Author:** ![Stephen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/stephen/32/102_2.png) [@Stephen](https://forum.canton.network/u/Stephen)\
**Post date:** [June 28, 2021, 3:58pm UTC](https://forum.canton.network/t/check-for-null-values-returned-from-fora/2766/3 "2021-06-28T15:58:26Z")

</div>

To put this another way, the pattern `[data1, data2]` _will not match_ if the list in question does not have exactly two elements.

Other languages have looser requirements here, which you may be thinking of. For example, I believe that if you do this destructuring in TypeScript or Common Lisp it will simply attach `undefined` or `NIL` to the extra variables. But in Daml, _if a variable is bound, it 100% refers to a valid value of the variable’s type, and will never fail when referenced_. So you can count on that being true for all patterns: if there isn’t a value to put there, the pattern will not succeed at all.

Putting a pattern on the left side of a `<-` has special error reporting behavior; in Daml, typically the transaction is aborted. Execution _never_ proceeds with the next line, because that would violate the rule about variables in Daml. Here’s how a pattern like yours would fail in an `Update`, such as defined for a choice:

```haskell
 Aborted: Pattern match failure in do expression at </path/to/filename>.daml:56:8-10

```

---

<div class="post-metadata">

**Author:** ![Pris17](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/pris17/32/2078_2.png) [@Pris17](https://forum.canton.network/u/Pris17)\
**Post date:** [June 28, 2021, 4:32pm UTC](https://forum.canton.network/t/check-for-null-values-returned-from-fora/2766/4 "2021-06-28T16:32:14Z")

</div>

@cocreature@Stephen Thanks for your reply

Can you provide more snippets or examples with Optional ?

---

<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:** [June 28, 2021, 5:20pm UTC](https://forum.canton.network/t/check-for-null-values-returned-from-fora/2766/5 "2021-06-28T17:20:42Z")

</div>

I recommend taking a look at the section on [variants in the daml intro](https://docs.daml.com/daml/intro/3_Data.html#variants-and-pattern-matching).
