[Haskell-beginners] LYAH example

sasa bogicevic brutallesale at gmail.com
Wed Mar 22 13:29:05 UTC 2017


Ahhhh I see, thank you very much for the response!

Have a nice day,
Sasa

{
	name: Bogicevic Sasa
	phone: +381606006200
}



> On Mar 22, 2017, at 13:30, Francesco Ariis <fa-ml at ariis.it> wrote:
> 
> 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
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



More information about the Beginners mailing list