<p>You can combine the two like this</p>
<pre><code>data DatumAction = VotingDatum | StartDatum
</code></pre>
<p>Then you can specify in you validator which case is used like this</p>
<pre><code>mkValidator :: DatumAction -&gt; redeemer -&gt; ScriptContext -&gt; Bool
mkValidator datumAction redeemer context = case datumAction of
    VotingDatum -&gt; do something with type bool
    StartDatum  -&gt; do something with type bool
</code></pre>
<p>Hope this helps, also see <a href="https://wiki.haskell.org/Algebraic_data_type" rel="nofollow noreferrer">(1)</a> and <a href="https://www.haskell.org/tutorial/patterns.html" rel="nofollow noreferrer">(2)</a>.</p>

CC BY-SA 4.0
2022-04-15T13:42:24.387Z
Yea , this is what i am looking for but I think i am missing something.It giving errors saying it couldn't match type StartDatum with type DatumAction and it couldnt match type VotingDatum with type Datum Action
szhang9921
CC BY-SA 4.0
2022-04-14T14:18:37.583Z
2022-04-14T14:18:37.583Z
Fermat
<p>I have two main actions that user can do. They both require sending utxos to a script address. The datum I want produced by these two actions are different. I want one of the datum like this</p>
<pre><code>data VotingDatum = VotingDatum
  { projectPubKey :: PaymentPubKeyHash
  , amount :: Integer
  , fund :: Integer
  , paymentPubKey :: PaymentPubKeyHash
  }deriving (Show)
</code></pre>
<p>and the other one like this.</p>
<pre><code>data StartDatum = StartDatum
 { startFund :: Integer
 , fundPrize :: Integer
 }deriving (Show)
</code></pre>
<p>I was thinking of putting these two in a single data type like this</p>
<pre><code>data ContractDatum = ContractDatum
 { voteDatum :: Maybe VotingDatum
 , startDatum :: Maybe StartDatum
 }
</code></pre>
<p>How would i set the value of these fields if i did it like this. Can i do it like this ?
I am currently setting the value of the types like this</p>
<pre><code>start sp = do 
    let dat = StartDatum
                { startFund = spFund sp 
                , fundPrize = spAmount sp
                }
</code></pre>
<p>How can i have two different data types for the datum. How can i set the value of it , and how would i access the value of it.</p>

<datum><data>
Different Data tyoes for datum
# Different Data tyoes for datum

(Asked by: username_0 on 2022-04-14)

I have two main actions that user can do. They both require sending utxos to a script address. The datum I want produced by these two actions are different. I want one of the datum like this
data VotingDatum = VotingDatum
  { projectPubKey :: PaymentPubKeyHash
  , amount :: Integer
  , fund :: Integer
  , paymentPubKey :: PaymentPubKeyHash
  }deriving (Show)

and the other one like this.
data StartDatum = StartDatum
 { startFund :: Integer
 , fundPrize :: Integer
 }deriving (Show)

I was thinking of putting these two in a single data type like this
data ContractDatum = ContractDatum
 { voteDatum :: Maybe VotingDatum
 , startDatum :: Maybe StartDatum
 }

How would i set the value of these fields if i did it like this. Can i do it like this ?
I am currently setting the value of the types like this
start sp = do 
    let dat = StartDatum
                { startFund = spFund sp 
                , fundPrize = spAmount sp
                }

How can i have two different data types for the datum. How can i set the value of it , and how would i access the value of it.

**Tags:** datum, data

---

## 1 answers

### Answer by username_1 on 2022-04-14. Score: 1 | Accepted answer

You can combine the two like this
data DatumAction = VotingDatum | StartDatum

Then you can specify in you validator which case is used like this
mkValidator :: DatumAction -> redeemer -> ScriptContext -> Bool
mkValidator datumAction redeemer context = case datumAction of
    VotingDatum -> do something with type bool
    StartDatum  -> do something with type bool

Hope this helps, also see (1) and (2).

> **Comments:**
> **username_0**: Yea , this is what i am looking for but I think i am missing something.It giving errors saying it couldn't match type StartDatum with type DatumAction and it couldnt match type VotingDatum with type Datum Action  

---

