# Inductive data type

**URL:** <https://discuss.ocaml.org/t/inductive-data-type/1746>\
**Category:** Learning\
**Created:** [March 20, 2018, 3:02pm UTC](https://discuss.ocaml.org/t/inductive-data-type/1746 "2018-03-20T15:02:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hughng92](https://avatars.discourse-cdn.com/v4/letter/h/f0a364/32.png) [@hughng92](https://discuss.ocaml.org/u/hughng92)\
**Post date:** [March 20, 2018, 3:02pm UTC](https://discuss.ocaml.org/t/inductive-data-type/1746/1 "2018-03-20T15:02:32Z")

</div>

Hello,  
I am working on the topic of inductive data type and I don’t quite understand the following type:  
type environment = (string \* value) list  
I am using this to define my new expression evaluation. For instance, I need to evaluate:

> ```
> Add (Int 4, Mul (Int 3, Id "x"))
> 
> ```

where

> ```
> type value 
> = Int of int | Bool of bool
> 
> type expr 
> = Val of value
> 
> | Add of expr * expr
> | Sub of expr * expr
> | Mul of expr * expr
> | Div of expr * expr 
> | Lt of expr * expr
> | Eq of expr * expr
> | And of expr * expr
> | Not of expr
> | Let of string * expr * expr
> | Id of string 
> 
> ```

what does this look like?  
How can I understand this new type environment?

I am guessing in my above expression:

> ```
> Add (Int 4, Mul (Int 3, Id "x"))
> 
> ```

I need to know what “x” is, so I need a sorta environment to convert “x” to a computational or operational variable that can be evaluated through an evaluation.  
But I am not sure how to correctly understand type environment.  
Please help.  
Thank you!

---

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [March 20, 2018, 4:40pm UTC](https://discuss.ocaml.org/t/inductive-data-type/1746/2 "2018-03-20T16:40:55Z")

</div>

Your expression contains `Id` elements. To evaluate an expression to a value, you need to know the value for each `Id`. This is provided by the environment: it should contain a value for each `Id` element that you find. You need a function like `lookup`

```auto
val lookup: string -> environment -> value
val eval: environment -> expr -> value

```

such that you can call `lookup "x" env` to get back `Int(42)` when you implement `eval`. In particular:

```auto
eval [("x", Int(42))] (Id "x") => Int(42)

```
