And is there any way to fix it so that I can use them outside as well?
Thanks in advance.
I have something like this:
if(x==1)
then
someList<-aFunction (1,2)
else
someList<-aFunction (3,4)
steps involving someList here
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have misunderstood variables in Haskell: once they are defined, they never change their value, so if you are hoping to do an assignment inside a branch, that won’t work. However, maybe the following helps:
Be careful not to read
xin the if-then-else unless you know what you’re doing 🙂 Another reminder: if you use anotherlet x = ..inside this construction, it will “shadow” the outerx, so it’ll effectively be a different, new variable.