Haskell name declaration rules -


i'm teaching myself haskell, , i've come across 2 implementations of "flip" function raise questions me name declaration.

these 2 same thing:

flip'' :: (a -> b -> c) -> b -> -> c   flip'' f y x = f x y    flip' :: (a -> b -> c) -> (b -> -> c)   flip' f = g       g x y = f y x   

the first example expect. in second example, i'm confused why we're allowed write g x y = f y x when haven't declared either x or y yet. understand lazy evaluation means neither evaluated until they're needed, expected compiler @ least want declaration.

it compiles without type signature... works fine:

flip' f = g       g x y = f y x  

so x , y untyped variables? or else going on? why able this?

i'm confused why we're allowed write g x y = f y x when haven't declared either x or y yet.

since g, x , y appear left of equal sign, are, in fact, declared. where introduces scope local code attached to. code written thus:

flip f = let g x y = f y x in g 

in english: let g function 2 arguments called x , y ....


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -