Haskell: List Comprehensions and higher-order functions -


I have tried to change the following list understanding:

  f xs = [x +8 |  

My first solution was:

  f (x, _) and lt; -xs]   

. 'Xs = map (\ (x, _) -> x + 8) xs

After trying several other approaches, I came to know that it also works :

  f 'xs = map ((+ 8) .fst) xs   

both versions of f same (Correct) output, but I do not understand why (+8) .fst is equal to \ (x, _) -> gt; X + 8 when using map on the list of tuples.

fst definition

  fst :: (a, b) - & gt; One FST (A, _) = a   

and (.) Is defined as

  (.) :: ( B -> C) - & gt; (A -> B) - & gt; A - & gt; C (fg) = \ x - & gt; F (gx)   

If we use these definitions to expand our work, then we should

  f 'xs = map ( +8) .fst. Xs f 'xs = map (\ x - & gt; (+8) (fst x)) - Definition of x - f' xs = map (\ x - & gt; (+8) ((, _ ) - & gt; a) x) - fst f 'xs = definition of map (\ (a, _) -> (+8) a) - We can specify the pattern' f 'xs = map \ (a, _) ) - & gt; a + 8) - extension section    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -