Lets say i have
data A = B Char Integer
and I have a variable called var in type A.
How can I access the integer value of var variable and use it?
Is there any operator to get it? I don't know, something like var->int would give me it?
You can define a function for this using pattern matching:
getIntegerFromA :: A -> Integer
getIntegerFromA (B _ int) = int
Though depending on where you want to use it, you can probably get the value using pattern matching right there instead of defining a separate function.
data A = B {charval :: Char, intval :: Integer}. Now you can use intval var to get at it.B 'c' 5 still works, as does pattern matching against it. See the heading "Labelled Fields" in the Online Report.