Variables in haskell

Let's say I have

data A = B Char Integer

and I have a var intype variable A. How can I access varand use the integer value of a variable ? Is there any operator to get it? I don’t know, something like var->intwill give me this?

+3
source share
2 answers

You can define a function for this using pattern matching:

getIntegerFromA :: A -> Integer
getIntegerFromA (B _ int) = int

Although depending on where you want to use it, you can probably get the value using a template that fits right there, instead of defining a separate function.

+6
source

- " ", , -Haskell .

+1

All Articles