The correct way to deal with changing variables in Haskell is with functions and recursion. To “change” the value of a variable you compute the new value and call some function with it. Then the function called will get that new value as it’s argument. Often this is a recursive call. Example with factorial below.
Imperative Pseudocode:
def factorial(n)
a=1
for i = 1 to n
a = a*i
return a
Translated to Haskell:
factorial n = go 1 1 where
go a i | i <= n = go (a*i) (i+1)
go a i | i > n = a
Notice that we replace the mutation of variables with a recursive call. Here is factorial in idiomatic Haskell:
factorial n = product [1..n]
Often one doesn’t really need values of variables to change at all.
Finally one should note that you aren’t actually changing the value of the variable var because your code is doing something like:
return 3 >>= \var ->
(... return (var +3)) >>= \var ->
..,
So you’re just doing what I described above in a very roundabout unidiomatic way.
let var = if (...) then 6 else 0...? If that's not satisfactory, you should maybe modify your motivating example to show why.