Programming Languages (CS302 2006S)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[CSC302 1999S]
Back to Haskell (1). On to Haskell (3).
Held: Wednesday, April 26, 2006
Summary: Today we continue our exploration of Haskell by considering data types and an example of using infinite lists.
Related Pages:
haskell.hs
, sample Haskell code.primes.hs
, our primes example.Due
Assignments
Notes:
Overview:
data Days = Mon | Tue | Wed | Thu | Fri | Sat | Sun data Gender = Male | Female | Unspecified
data Person = Per String Int Gender
Per
is the constructor, which takes
three arguments:
data IntList = ILnil | ILcons Int IntList
data List a = Nil | Cons a (List a)
Cons
, car
, and cdr
.
car (Cons x xs) = x cdr (Cons x xs) = xs
definedby a series of equations like this.
Push
, NewStack
, top
,
pop
and empty
.
data Stack a = NewStack | Push a (Stack a) pop :: Stack a -> Stack a pop (Push item stack) = stack pop NewStack = error top :: Stack a -> a top (Push item stack) = item top NewStack = error empty :: Stack a -> Bool empty NewStack = True empty (Push item stack) = False
Back to Haskell (1). On to Haskell (3).
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[CSC302 1999S]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Wed May 10 09:03:05 2006.
The source to the document was last modified on Thu Jan 12 09:00:38 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS302/2006S/Outlines/outline.35.html
.
You may wish to
validate this document's HTML
;
;
Check with Bobby