Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is it possible that a binding shadows the existing binding in `case of` block?

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?

like image 360
mkUltra Avatar asked Aug 25 '19 15:08

mkUltra


1 Answers

Haskell's let is actually letrec.

In let x = x in ..., the x on the right refers to the x on the left.

The scope of x, y and z in

    let 
       x = ...
       y = ...
       z = ...
    in ...

are all the code areas indicated with ....

like image 105
Will Ness Avatar answered Nov 02 '22 23:11

Will Ness