# Error when trying to define a generic function

**URL:** <https://forum.canton.network/t/error-when-trying-to-define-a-generic-function/153>\
**Category:** App Development\
**Tags:** daml\
**Created:** [April 16, 2020, 10:43am UTC](https://forum.canton.network/t/error-when-trying-to-define-a-generic-function/153 "2020-04-16T10:43:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vivek\_Srivastava](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/vivek_srivastava/32/79_2.png) [@Vivek\_Srivastava](https://forum.canton.network/u/Vivek_Srivastava)\
**Post date:** [April 16, 2020, 10:43am UTC](https://forum.canton.network/t/error-when-trying-to-define-a-generic-function/153/1 "2020-04-16T10:43:04Z")

</div>

![Screenshot 2020-04-16 at 11.22.34](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/1X/a7d7d38fc85b13aa98c71a31b2850af1ec7ed710.png)

Help please!!

---

<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:** [April 16, 2020, 10:46am UTC](https://forum.canton.network/t/error-when-trying-to-define-a-generic-function/153/2 "2020-04-16T10:46:54Z")

</div>

If you hover over the `addGen` function (you might have to temporarily comment out line 25 so the file compiles) you can see that it has the signature `addGen : Additive a => a -> a -> a` so as desired it is generic here.

Now when you try to use it in line 25 the compiler needs to figure out which type `a` should be. You are using a literal with a decimal point which means that it will be a value of type `Numeric n` for some number `n`. The numeric type allows for different scales (number of digits after the decimal point). A very common case is `Decimal` which is a synonym for `Numeric 10`. In your example there is no further information to help the compiler figure out which `n` you want. If you add a type annotation and change line 25 as follows , the error goes away:

```haskell
assert (addGen (6.0 : Numeric 10) 4.0 == 10.0)

```

---

<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:** [April 16, 2020, 1:13pm UTC](https://forum.canton.network/t/error-when-trying-to-define-a-generic-function/153/3 "2020-04-16T13:13:38Z")

</div>

Could this also be solved by making the `addGen` type signature less generic? (ie. is there a type that handles all kinds of numbers?)

Also @Vivek_Srivastava please post example code as text and not screenshots so that those answering can copy/paste the code to test it, and those searching the forums have an easier time finding it.

You can put all your code between 3 backticks (```) so it gets formatted nicely, so for example entering the following:

````
```
addGen x y = x + y
assert (addGen 6.0 4.0 == 10.0)
```

````

Would give you:

```haskell
addGen x y = x + y
assert (addGen 6.0 4.0 == 10.0)

```

---

<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:** [April 16, 2020, 1:15pm UTC](https://forum.canton.network/t/error-when-trying-to-define-a-generic-function/153/4 "2020-04-16T13:15:06Z")

</div>

Sure you can make it less generic but the question was explicitly about defining a generic function.

If you want to make it less generic, you can go for

```haskell
addGen : Numeric 10 -> Numeric 10 -> Numeric 10
addGen x y = x + y

```
