funkcionalno programiranje
Download
Skip this Video
Download Presentation
Funkcionalno programiranje

Loading in 2 Seconds...

play fullscreen
1 / 14

Funkcionalno programiranje - PowerPoint PPT Presentation


  • 126 Views
  • Uploaded on

Funkcionalno programiranje. Čas7: Rad sa beskonačnim listama Primeri rada sa matricama. Pitagorejske trojke. Zadatak:

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Funkcionalno programiranje' - quincy


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
funkcionalno programiranje

Funkcionalno programiranje

Čas7:

Rad sa beskonačnim listama

Primeri rada sa matricama

pitagorejske trojke
Pitagorejske trojke
  • Zadatak:

Pitagorejska trojkaje svaka trojka prirodnih brojeva (x,y,z) koja ispunjava uslov x*x+y*y=z*z. Napisati funkciju pythagTripleskoja generiše listu svih pitagorejskih trojki.

pogre no re enje
pogrešno rešenje

pythagTriplesWrong= [ (x,y,z) |

x<-[2..],

y<-[x+1..],

z<-[y+1..],

x*x+y*y=z*z]

t a no re enje
tačno rešenje

pythagTriples = [ (x,y,z) |

z<-[2..],

y<-[2..z-1],

x<-[2..y-1],

x*x+y*y=z*z]

generisanje slu ajnih brojeva
Generisanje slučajnih brojeva
  • Linearni kongruentni metod:

Xn+1 = (aXn+c) mod m

m>0 - modulus

0<a<m – multiplier

0<=c <m – increment

0<=Xo<=m – seed

primer
Primer
  • rand.hs
podse anje
Podsećanje
  • funkcija all

all :: (a → Bool ) → [a ] → Bool

all p = and ◦ map p

Npr all (>0) [1,2,3]

slide8
Karijeve funkcije:
  • add :: (Int, Int) → Int
  • add’ :: Int → (Int → Int)
slide9
funkcije curry:
  • Curry pretvara funkciju nad parovima u Karijevu funkciju:

curry :: ((a, b) → c) → (a → b → c)

curry f = λx y → f (x , y)

Primer: curry fst 1 2

slide10
funkcija uncurry:
  • Pretvara Karijevu funkciju u funkciju nad parovima:

uncurry :: (a → b → c) → ((a, b) → c)

uncurry f = λ(x , y) → f x y

Npr. uncurry (+) (1,2)

slide11
Funkcija zip:

zip :: [a ] → [b ] → [(a, b)]

Primer:

> zip [’a’, ’b’, ’c’] [1, 2, 3, 4]

[(’a’, 1), (’b’, 2), (’c’, 3)]

slide12
Funkcija zipWith

zipWith f [] _ = []

zipWith f _ [] = []

zipWith f (x:xs) (y:ys) = f x y : zipWith f xs ys

Primer: zipWith (*) [1,2] [3,4]

rad sa matricama
Rad sa matricama
  • type Matrix = [[Int]]
  • zadaci06.txt
rad sa matricama1
Rad sa matricama
  • primer: inverse.hs
ad