On Wed, Mar 22, 2017 at 12:44:23PM +0100, sasa bogicevic wrote:

> Hi All,

> Can someone clarify the example I got from LYAH book. This let statement

> is kinda confusing to me :

>

> applyLog :: (a, String) -> (a -> (b, String)) -> (b, String)

> applyLog (x, log) f = let (y, newLog) = f x in (y, log ++ newLog)

Hello Sasa,

let's rewrite `applyLog`:

applyLog :: (a, String) -> (a -> (b, String)) -> (b, String)

applyLog (x, log) f =

-- f :: a -> (b, String)

let (y, newLog) = f x -- y :: b

-- newLog :: String

in (y, log ++ newLog) -- (b, String)

f applied to x doesn't produce just `y`, but `y` and `newLog` (in

a Tuple). It is perfectly ok to specify a pattern:

let (y, newLog) = f x -- legal

let xyz = f x -- legal too. The first form saves you a `fst`/`snd`

Is it clearer now?

_______________________________________________

Beginners mailing list

[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners