12.07.2015 Views

CSCE 314 Programming Languages - TAMU Computer Science ...

CSCE 314 Programming Languages - TAMU Computer Science ...

CSCE 314 Programming Languages - TAMU Computer Science ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using zip we can define a function that returns the listof all pairs of adjacent elements from a list:pairs :: [a] -> [(a,a)]pairs xs = zip xs (tail xs)> pairs [1,2,3,4][(1,2),(2,3),(3,4)]Using pairs we can define a function that decides if theelements in a list are sorted:sorted :: Ord a => [a] -> Boolsorted xs = and [x ≤ y | (x,y) sorted [1,2,3,4]True> sorted [1,3,2,4]False30

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!