CSCE 314 Programming Languages - TAMU Computer Science ...
CSCE 314 Programming Languages - TAMU Computer Science ...
CSCE 314 Programming Languages - TAMU Computer Science ...
- No tags were found...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
A positive integer is prime if its only factors are 1 anditself. Hence, using factors we can define a function thatdecides if a number is prime:prime :: Int -> Boolprime n = factors n == [1,n]> prime 15False> prime 7TrueUsing a guard we can now define a function that returnsthe list of all primes up to a given limit:primes :: Int -> [Int]primes n = [x | x primes 40[2,3,5,7,11,13,17,19,23,29,31,37]28