I have to extract user name and email from Either
of AuthResponse
.
I use case of
construct for it:
let (uname, uemail) =
case getUserResponseJSON creds of
Right (GoogleUserResponse uname uemail) -> (uname, uemail)
_ -> ("", "")
But I have this warning for both uname
and uemail
:
This binding for ‘uname’ shadows the existing binding
bound at src/Foundation.hs:240:12
|
242 | Right (GoogleUserResponse uname uemail) -> (uname, uemail)
|
I expect that let (uname, uemail)
is out of the scope of case of
block.
How is it possible to have this warning from the case
block if uname
and uemail
are not yet defined?
How is possible to have this warning from the case block if uname and uemail still not defined?
These are defined, in the scope outside the case
, two variables named uname
and uemail
are defined. The Haskell compiler can "tie a knot". Take for example the following expression where we define an endless list of ones:
ones :: [Int]
ones = x
where x = 1 : x
Here we thus define a list that looks like:
+-------+
| (:) |<,
+---+---+ |
| o | o---'
+-|-+---+
v
1
So you can define a variable in terms of itself, like you do here. You do not assign a value to variable, you declare a variable. Furthermore note that the order in which you define variables is not per se the order in which you will perform operations. So it is possible that the (uname, uemail)
is never evaluated, etc.