# Can a Choice in Daml conditionally return more than one type?

**URL:** <https://forum.canton.network/t/can-a-choice-in-daml-conditionally-return-more-than-one-type/2749>\
**Category:** App Development\
**Tags:** choices\
**Created:** [June 23, 2021, 6:15pm UTC](https://forum.canton.network/t/can-a-choice-in-daml-conditionally-return-more-than-one-type/2749 "2021-06-23T18:15:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthony](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/anthony/32/419_2.png) [@anthony](https://forum.canton.network/u/anthony)\
**Post date:** [June 23, 2021, 6:15pm UTC](https://forum.canton.network/t/can-a-choice-in-daml-conditionally-return-more-than-one-type/2749/1 "2021-06-23T18:15:14Z")

</div>

Choices are typically defined like:

```haskell
    controller sig can
      Switch : ContractId TemplateA
        with
          cond : Int
        do

```

How would I return `TemplateA` OR `TemplateB`?

---

<div class="post-metadata">

**Author:** ![anthony](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/anthony/32/419_2.png) [@anthony](https://forum.canton.network/u/anthony)\
**Post date:** [June 23, 2021, 6:17pm UTC](https://forum.canton.network/t/can-a-choice-in-daml-conditionally-return-more-than-one-type/2749/2 "2021-06-23T18:17:37Z")

</div>

I could use a sum type, or the built-in type Either (if I only had two things to return), as below:

The one caveat with using Either is that it’s commonly understood that `Left` is treated as an error and `Right` is treated as a success. This doesn’t need to be the case and isn’t enforced by the type but is a fairly common construct.

```haskell
module SumTypes where
import Daml.Script

-- Sum Type
data TemplateChoice a b c = ChoiceA a | ChoiceB b | ChoiceC c

template TemplateA with
    sig: Party
  where
    signatory sig

template TemplateB with
    sig: Party
  where
    signatory sig

template TemplateC with
    sig: Party
  where
    signatory sig

template Test with
    sig: Party
  where
    signatory sig
    controller sig can
      Switch : TemplateChoice (ContractId TemplateA) (ContractId TemplateB) (ContractId TemplateC)
        with
          cond : Int
        do
          case cond of
            0 -> do 
              a <- create TemplateA with ..
              return (ChoiceA a)
            1 -> do
              b <- create TemplateB with ..
              return (ChoiceB b)
            _ -> do
              c <- create TemplateC with ..
              return (ChoiceC c)

test: Script ()
test = do
  alice <- allocateParty "Alice"
  testContract <- submit alice $ do createCmd Test with sig = alice
  contractChoiceExercised <- submit alice $ do exerciseCmd testContract Switch with cond = 1
  return ()
  
  
--------- The Either version of the above:

template TestEither with
    sig: Party
  where
    signatory sig
    controller sig can
      TestEither_Switch : Either (ContractId TemplateA) (ContractId TemplateB)
        with
          cond : Bool
        do
          if cond
            then do
              a <- create TemplateA with ..
              return (Left a)
            else do
              b <- create TemplateB with ..
              return (Right b)

```
