user2925688
user2925688

Reputation: 217

Haskell let-in Construct

Why is the result of these two functions not equivalent?

mnr = [0,1,2,3,4,5,6]  :: [Int]
name = "Max Mustermann" :: String

t1 = ("p1",(length.take 2)mnr, (take 2.(let no name = name;in no))"No");
{- ("p1",2,"No") -}

t1' = ("p1",(length.take 2)mnr, (take 2.(let no n = name;in no))"No");
{- ("p1",2,"Ma") -}

The only difference in these functions is the name of the variable in let.

Best regards, Stefan

Upvotes: 1

Views: 270

Answers (1)

Dan
Dan

Reputation: 13160

If you turn on -Wall, you will see a warning in t1 that name shadows the existing binding for name:

let no name = name
       ^^^^--- this one

shadows

name = "Max Mustermann" :: String

So the name inside the function is the argument, making the function the same as id, while in t2 the name:

let no n = name

is the one defined at top-level.

Upvotes: 10

Related Questions