A Quick Taste of Haskell (I)

 Willamette Mathematics Colloquium • Fall 2002

A Quick Taste of Haskell (I)
 An introduction to Haskell through examples we give the flavor of Haskell via examples in the Hugs interactive interpreter (in the talk itself, we hope to run these examples "live")

 Willamette Mathematics Colloquium • Fall 2002

A Quick Taste of Haskell (I)
 An introduction to Haskell through examples Simple arithmetic, large integers simple calculation can be done at the interactive prompt > 2 + 3 * 5 17 > 37^37 10555134955777783414078330085995832946127396083370199442517

 Willamette Mathematics Colloquium • Fall 2002

A Quick Taste of Haskell (I)
 An introduction to Haskell through examples Simple arithmetic, large integers Exact rational arithmetic Haskell provides exact rational numbers (written with an infix "%") as a safer alternative to floating-point > 51 % 3 17 % 1 > (51 % 3) * (2 % 5) 34 % 5

 Willamette Mathematics Colloquium • Fall 2002

A Quick Taste of Haskell (I)
 An introduction to Haskell through examples Simple arithmetic, large integers Exact rational arithmetic Floating-point arithmetic Traditional IEEE floating-point arithmetic is also available (with the usual caveats) > 2.3 ^ 5 64.36343 > \$\$ * 25.333 1630.51877

 Willamette Mathematics Colloquium • Fall 2002

A Quick Taste of Haskell (I)
 An introduction to Haskell through examples Simple arithmetic, large integers Exact rational arithmetic Floating-point arithmetic Pairs and tuples Unlike most languages, Haskell provides pairs and tuples as independent entities (e.g., to return multiple results) > 17 `divMod` 3 (5,2) > 17 `divMod` 3 (5,2)

 Willamette Mathematics Colloquium • Fall 2002

A Quick Taste of Haskell (I)
 An introduction to Haskell through examples Simple arithmetic, large integers Exact rational arithmetic Floating-point arithmetic Pairs and tuples Lists of numbers (ellipsis notation) we can easily generate and manipulate lists of numbers > [1..12] [1,2,3,4,5,6,7,8,9,10,11,12] > sum [1..10] 55 > product [1..10] 3628800

 Willamette Mathematics Colloquium • Fall 2002

A Quick Taste of Haskell (I)
 An introduction to Haskell through examples Simple arithmetic, large integers Exact rational arithmetic Floating-point arithmetic Pairs and tuples Lists of numbers (ellipsis notation) Z-F expressions another notational convenience (due to David Turner) is list comprehension, which mimics notation from Zermelo-Fraenkel set theory > [ a * b | a<-[1..3], b<-reverse [1..4] ] [4,3,2,1,8,6,4,2,12,9,6,3] > [ 2^i | i<-[1..20], odd i] [2,8,32,128,512,2048,8192,32768,131072,524288]

 Willamette Mathematics Colloquium • Fall 2002

A Quick Taste of Haskell (I)
 An introduction to Haskell through examples Simple arithmetic, large integers Exact rational arithmetic Floating-point arithmetic Pairs and tuples Lists of numbers (ellipsis notation) Z-F expressions Strings and list operations > replicate 3 "hello" ["hello","hello","hello"] > words "This is a sample text" ["This","is","a","sample","text"] > unwords (reverse \$\$) "text sample a is This"