Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pp:21:laboratoare:haskell:intro [2021/04/05 12:24]
bot.pp
pp:21:laboratoare:haskell:intro [2021/04/05 15:18] (current)
bot.pp
Line 882: Line 882:
 <code lisp> <code lisp>
 ; map ; map
-(map (λ (x) (+ x 1)) (list 1 2 3 4)) +(map (λ (x) (+ x 1)) (list 1 2 3 4)) ; '(2 3 4 5
-(map add1 (list 1 2 3 4))+(map add1 (list 1 2 3 4)) ; '(2 3 4 5)
  
 ; filter ; filter
-(filter (λ (x) (equal? (modulo x 2) 0)) (list 1 2 3 4 5 6))+(filter (λ (x) (equal? (modulo x 2) 0)) (list 1 2 3 4 5 6)) ; '(2 4 6)
  
 ; foldl ; foldl
-(reverse (foldl (lambda (x acc) (cons x acc)) '() (list 1 2 3 4 5)))+(reverse (foldl (lambda (x acc) (cons x acc)) '() (list 1 2 3 4 5))) ; '(1 2 3 4 5)
  
 ; foldr ; foldr
-(foldr (lambda (x acc) (cons x acc)) '() (list 1 2 3 4 5))+(foldr (lambda (x acc) (cons x acc)) '() (list 1 2 3 4 5)) ; '(1 2 3 4 5)
  
 </​code>​ </​code>​
Line 899: Line 899:
 <​code>​ <​code>​
 -- map -- map
-map (\x -> x + 1) [1, 2, 3, 4] +map (\x -> x + 1) [1, 2, 3, 4] -- [2, 3, 4, 5
-map (+ 1) [1, 2, 3, 4]+map (+ 1) [1, 2, 3, 4] -- [2, 3, 4, 5]
  
 -- filter -- filter
-filter (\x -> mod x 2 == 0) [1, 2, 3, 3, 4, 5, 6]+filter (\x -> mod x 2 == 0) [1, 2, 3, 3, 4, 5, 6] -- [2, 4, 6]
  
 -- foldl -- foldl
Line 912: Line 912:
  
 </​code>​ </​code>​
 +Un fapt notabil în ceea ce diferența dintre Haskell și Racket este în faptul că diferă ordinea parametrilor la funcția anonimă dată ca parametru între tipurile de fold (în Racket nu diferă ordinea, care este element -> acumulator, acest fapt se poate observa în exemplele de mai sus), mai precis:
 +
 +  * ''​%%foldl%%'':​ acumulator -> element
 +  * ''​%%foldr%%'':​ element -> acumulator
 +
 Legări: Legări:
  
pp/21/laboratoare/haskell/intro.1617614688.txt.gz · Last modified: 2021/04/05 12:24 by bot.pp
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0