2 Pages

Haskell

Course: CSE 382, Spring 2009
School: Taylor IN
Rating:
 
 
 
 
 

Word Count: 469

Document Preview

University Taylor Computer Science and Engineering Bill Toll Spring 2009 COS 382 Language Structures Haskell The Sieve of Eratosthenes ASSIGNED: May 4, 2009 DUE: May 13, 2009 SUBMISSION: Submit your Haskell program as a .hs file through moodle. NOTE: This assignment is to be done individually. Overview The purpose of this assignment is to write Haskell functions to generate prime numbers. We will take...

Register Now

Unformatted Document Excerpt

Coursehero >> Indiana >> Taylor IN >> CSE 382

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
University Taylor Computer Science and Engineering Bill Toll Spring 2009 COS 382 Language Structures Haskell The Sieve of Eratosthenes ASSIGNED: May 4, 2009 DUE: May 13, 2009 SUBMISSION: Submit your Haskell program as a .hs file through moodle. NOTE: This assignment is to be done individually. Overview The purpose of this assignment is to write Haskell functions to generate prime numbers. We will take advantage of the lazy evaluation feature of Haskell to generate inifinite lists used in a sieve approach. This assignment is based on an assignment used by Dr. Neil Leslie in the Programming Languages course at Victoria University of Wellington in New Zealand. The Sieve of Eratosthenes is an ancient technique to generate prime numbers dating to the 3rd century BC. The algorithm uses no division but rather generates composite numbers and defines primes as non-composites. A prime number is a number with no divisors other than 1 and itself. A composite number is one with divisors other than 1 and itself. Technique We will use 3 lists. The first is a list of all possible primes. The second is a list of composite numbers discovered at a given time. The third is a list of primes discovered at a given time. Our approach will be to look for primes in the sequence {2, 3, 4, 5, . . . } We begin with an empty list of composites and an empty list of primes. Look at the first item in the sequence (2). Since it is not in our list of composites, it is prime. Therefore, add 2 to the the list of primes and add all multiples 2 of (beginning at 4) to our list of composites. Next, look at the first number in the sequence {3, 4, 5, . . . } Since 3 is not in the list of composites, it is prime and is added to the list of primes, All multiples of 3 (beginning with 9) are added to the list of composites. Next, check 4. It is in the list of composites and is not added to the list or primes, nor are any numbers added to the list of composites. Requirements Write the following Haskell functions. Prods:: Int [Int] prods n generates the infinite list of products of n beginning with n^2 prods 3 [9, 12, 15, 18, 21, . . . ] mix:: [Int] [Int] [Int] mix takes 2 infinite lists (each assumed to be in order) and merges them into a single infinite list in order with no duplicates mix (prods 5) (prods 7) [25, 30, 35, 40, 45, 49, 50, 55, 56, 60, 63, . . . ] sieve:: [Int] [Int] [Int] sieve implements the Sieve of Eratosthenes. The first ...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Taylor IN - CSE - 382
Taylor University Computer Science and Engineering Bill Toll Spring 2009COS 382 Language Structures Infix Grammar suitable for RDP start list list EOF listexpr ; | empty termexpr moreterms moreterms moreterms moreterms+ term | term |
Taylor IN - CSE - 382
Taylor University Computer Science and Engineering Bill Toll Spring 2009COS 382 Language Structures Infix Grammar including semantic actions to translate to RPN suitable for RDP start list list EOF {dumptable} {print expression} listexpr ; |
Taylor IN - CSE - 382
Taylor University Computer Science and Engineering Bill Toll Spring 2009COS 382 Language Structures Lexical Analyzers Lexical analyzers can be written in a variety of languages and with somewhat different approaches. The important similarity is t
Taylor IN - CSE - 382
Taylor University Computer Science and Engineering Bill Toll Spring 2009COS 382 Language Structures Prolog Simple Natural Language Processing ASSIGNED: May 1, 2009 DUE: May 8, 2009 SUBMISSION: Submit your Prolog program, documentation, etc as a z
Taylor IN - CSE - 382
Taylor University Computer Science and Engineering Bill Toll Spring 2009 COS 382 Language StructuresScripture Reference GrammarExamplesJohn 1 John 1:24 Ps 12:1,34 Rev 2:4;4:5 (NIV) NOTE: Matt 2:33:1 is not allowed S BRT B ON R X X;R empt
Taylor IN - CSE - 382
COS 382 Language StructuresANTLR TutorialExpression GrammarsExample grammars and explanation from Expression Evaluator Tutorial, www.antlr.org/works/help/tutorial/calculator.html1Basic Expression GrammarThis grammar represents arithmetic
UC Davis - ARCHIVE - 042406
TEACHER AGREEMENTFood Stamp Nutrition Education ProgramTeacher _School _ School Address: Street _ City __ State_ Zip Code _ Gender: (check one) _ Female _ Male Race/Ethnicity: (check one) _ White (non-Hispanic) _ Amer. Indian/Alaskan Native _ Asia
Taylor IN - CSE - 382
4/13/2009 : 031309Panel 1Panel 2Page 1 of 174/13/2009 : 031309Panel 3Panel 4Page 2 of 174/13/2009 : 031309Panel 5Panel 6Page 3 of 174/13/2009 : 031309Panel 7Panel 8Page 4 of 174/13/2009 : 031309Panel 9Panel 10Pag
Taylor IN - CSE - 382
4/13/2009 : 031609Panel 1Panel 2Page 1 of 154/13/2009 : 031609Panel 3Panel 4Page 2 of 154/13/2009 : 031609Panel 5Panel 6Page 3 of 154/13/2009 : 031609Panel 7Panel 8Page 4 of 154/13/2009 : 031609Panel 9Panel 10Pag
Taylor IN - CSE - 382
4/13/2009 : 031809Panel 1Panel 2Page 1 of 44/13/2009 : 031809Panel 3Panel 4Page 2 of 44/13/2009 : 031809Panel 5Panel 6Page 3 of 44/13/2009 : 031809Panel 7Panel 8Page 4 of 4
Taylor IN - CSE - 382
4/13/2009 : 032009Panel 1Panel 2Page 1 of 94/13/2009 : 032009Panel 3Panel 4Page 2 of 94/13/2009 : 032009Panel 5Panel 6Page 3 of 94/13/2009 : 032009Panel 7Panel 8Page 4 of 94/13/2009 : 032009Panel 9Panel 10Page 5
Taylor IN - CSE - 382
4/13/2009 : 033009Panel 1Panel 2Page 1 of 134/13/2009 : 033009Panel 3Panel 4Page 2 of 134/13/2009 : 033009Panel 5Panel 6Page 3 of 134/13/2009 : 033009Panel 7Panel 8Page 4 of 134/13/2009 : 033009Panel 9Panel 10Pag
Taylor IN - CSE - 382
4/13/2009 : 040109Panel 1Panel 2Page 1 of 194/13/2009 : 040109Panel 3Panel 4Page 2 of 194/13/2009 : 040109Panel 5Panel 6Page 3 of 194/13/2009 : 040109Panel 7Panel 8Page 4 of 194/13/2009 : 040109Panel 9Panel 10Pag
Taylor IN - CSE - 382
4/13/2009 : 040309Panel 1Panel 2Page 1 of 204/13/2009 : 040309Panel 3Panel 4Page 2 of 204/13/2009 : 040309Panel 5Panel 6Page 3 of 204/13/2009 : 040309Panel 7Panel 8Page 4 of 204/13/2009 : 040309Panel 9Panel 10Pag
Taylor IN - CSE - 382
4/13/2009 : 040609Panel 1Panel 2Page 1 of 204/13/2009 : 040609Panel 3Panel 4Page 2 of 204/13/2009 : 040609Panel 5Panel 6Page 3 of 204/13/2009 : 040609Panel 7Panel 8Page 4 of 204/13/2009 : 040609Panel 9Panel 10Pag
Taylor IN - CSE - 382
4/13/2009 : 040809Panel 1Panel 2Page 1 of 184/13/2009 : 040809Panel 3Panel 4Page 2 of 184/13/2009 : 040809Panel 5Panel 6Page 3 of 184/13/2009 : 040809Panel 7Panel 8Page 4 of 184/13/2009 : 040809Panel 9Panel 10Pag
Taylor IN - CSE - 382
5/6/2009 : 041509Panel 1Panel 2Page 1 of 125/6/2009 : 041509Panel 3Panel 4Page 2 of 125/6/2009 : 041509Panel 5Panel 6Page 3 of 125/6/2009 : 041509Panel 7Panel 8Page 4 of 125/6/2009 : 041509Panel 9Panel 10Page 5 o
Taylor IN - CSE - 382
5/6/2009 : 042009Panel 1Panel 2Page 1 of 95/6/2009 : 042009Panel 3Panel 4Page 2 of 95/6/2009 : 042009Panel 5Panel 6Page 3 of 95/6/2009 : 042009Panel 7Panel 8Page 4 of 95/6/2009 : 042009Panel 9Panel 10Page 5 of 9
Taylor IN - CSE - 382
5/6/2009 : 042209Panel 1Panel 2Page 1 of 105/6/2009 : 042209Panel 3Panel 4Page 2 of 105/6/2009 : 042209Panel 5Panel 6Page 3 of 105/6/2009 : 042209Panel 7Panel 8Page 4 of 105/6/2009 : 042209Panel 9Panel 10Page 5 o
Taylor IN - CSE - 382
5/6/2009 : 042409Panel 1Panel 2Page 1 of 245/6/2009 : 042409Panel 3Panel 4Page 2 of 245/6/2009 : 042409Panel 5Panel 6Page 3 of 245/6/2009 : 042409Panel 7Panel 8Page 4 of 245/6/2009 : 042409Panel 9Panel 10Page 5 o
Taylor IN - CSE - 382
5/6/2009 : 042709Panel 1Panel 2Page 1 of 125/6/2009 : 042709Panel 3Panel 4Page 2 of 125/6/2009 : 042709Panel 5Panel 6Page 3 of 125/6/2009 : 042709Panel 7Panel 8Page 4 of 125/6/2009 : 042709Panel 9Panel 10Page 5 o
Taylor IN - CSE - 382
5/6/2009 : 042909Panel 1Panel 2Page 1 of 155/6/2009 : 042909Panel 3Panel 4Page 2 of 155/6/2009 : 042909Panel 5Panel 6Page 3 of 155/6/2009 : 042909Panel 7Panel 8Page 4 of 155/6/2009 : 042909Panel 9Panel 10Page 5 o
Taylor IN - CSE - 382
5/6/2009 : 050409Panel 1Panel 2Page 1 of 125/6/2009 : 050409Panel 3Panel 4Page 2 of 125/6/2009 : 050409Panel 5Panel 6Page 3 of 125/6/2009 : 050409Panel 7Panel 8Page 4 of 125/6/2009 : 050409Panel 9Panel 10Page 5 o
Taylor IN - CSE - 382
5/6/2009 : 050609Panel 1Panel 2Page 1 of 55/6/2009 : 050609Panel 3Panel 4Page 2 of 55/6/2009 : 050609Panel 5Panel 6Page 3 of 55/6/2009 : 050609Panel 7Panel 8Page 4 of 55/6/2009 : 050609Panel 9Panel 10Page 5 of 5
Taylor IN - CSE - 382
5/15/2009 : 051309Panel 1Panel 2Page 1 of 135/15/2009 : 051309Panel 3Panel 4Page 2 of 135/15/2009 : 051309Panel 5Panel 6Page 3 of 135/15/2009 : 051309Panel 7Panel 8Page 4 of 135/15/2009 : 051309Panel 9Panel 10Pag
Taylor IN - CSE - 382
5/15/2009 : 051509Panel 1Panel 2Page 1 of 95/15/2009 : 051509Panel 3Panel 4Page 2 of 95/15/2009 : 051509Panel 5Panel 6Page 3 of 95/15/2009 : 051509Panel 7Panel 8Page 4 of 95/15/2009 : 051509Panel 9Panel 10Page 5
Taylor IN - CSE - 382
Taylor University Computer Science and Engineering Bill Toll Spring 2009 COS 382 Language StructuresExampleS ABC ABCD A X X.A empty B N N:B C X X.A empty D N X digit digitX N letter letterN digit ' 0 ' . ' 9 ' letter 'a' . . 'z' '
Taylor IN - CSE - 424
Patches: 32Index: 11 2 3 4 5 6 7 8 9 10 11 12 13 14 15 164 17 18 19 8 20 21 22 12 23 24 25 16 26 27 2819 29 30 31 22 32 33 34 25 35 36 37 28 38 39 4031 41 42 1 34 43 44 5 37 45 46 9 40 47 48 1313 14 15 16 49 50 51 52 53 54 55 56 57 58 59 6016
Taylor IN - CSE - 424
2/9/2009 : 020109Panel 1Panel 2Page 1 of 132/9/2009 : 020109Panel 3Panel 4Page 2 of 132/9/2009 : 020109Panel 5Panel 6Page 3 of 132/9/2009 : 020109Panel 7Panel 8Page 4 of 132/9/2009 : 020109Panel 9Panel 10Page 5 o
Taylor IN - CSE - 424
2/9/2009 : 020409Panel 1Panel 2Page 1 of 32/9/2009 : 020409Panel 3Panel 4Page 2 of 32/9/2009 : 020409Panel 5Panel 6Page 3 of 3
Taylor IN - CSE - 424
2/13/2009 : 021309Panel 1Panel 2Page 1 of 152/13/2009 : 021309Panel 3Panel 4Page 2 of 152/13/2009 : 021309Panel 5Panel 6Page 3 of 152/13/2009 : 021309Panel 7Panel 8Page 4 of 152/13/2009 : 021309Panel 9Panel 10Pag