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 09:22]
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:
  
   * Racket   * Racket
 +
 +<code lisp>
 +(define (f a) 
 +    (let ((c a) (b (+ a 1))) 
 +        (+ c b)))
 +        ​
 +(define (g a) 
 +    (let* ((c a) (b (+ c 1))) 
 +        (+ c b)))
 +    ​
 +;(define (h a) 
 +;    (letrec ((c b) (b (+ a 1))) 
 +;        (+ c b)))               ; aici vom avea eroare, pentru ca la legarea lui b la c, b-ul nu este definit
 +
 +</​code>​
   * Haskell - ''​%%let%%''​ în Haskell se comporta precum ''​%%letrec%%''​ din Racket   * Haskell - ''​%%let%%''​ în Haskell se comporta precum ''​%%letrec%%''​ din Racket
  
pp/21/laboratoare/haskell/intro.1617603770.txt.gz · Last modified: 2021/04/05 09:22 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