Assignment 1
CIS 252 Intro to Computer Science
Coverage
This homework covers material through the rst two chapters of Haskell: The Craft of Functional
Programming (HCFP).
Logistics
This homework is oc
Assignment 6
CIS 252 Intro to Computer Science
Coverage & Logistics
12) represents the Queen of Hearts. We represent packs (a collection of cards) with
values of the type
This assignment covers materi
Lab 6: Getting Started with Type Classes and Algrebraic Types
1. Introduction
This lab will give you some practice in working with Haskells type classes.
When you introduce a new data type in Haskell,
Lab 1: Hello World
This lab will introduce you to some of the key tools we will be using in
this course. In many labs, you are allowed to work together with a partner. However, this lab must be a solo
Lab 10: A Types Scavenger Hunt
Overview
This lab gives you some more practice with types, especially as they relate to
functions and function applications. Every valid Haskell expression has some
pred
Lab 5: Patterns for List Processing
Overview. This lab gives you some practice with some common idioms for
list processing. These idiomsmapping, filtering, and foldingare so common
that Haskell (and m
Lab 3: Pictures of Recursion
Overview
This lab will give you practice with writing recursive functions in Haskell, using
the Pictures module (http:/www.cis.syr.edu/courses/cis252/code/
Pictures.lhs) f
Lab 2: Getting Familiar with Haskell & Hugs
You may work singly or in pairs on this lab.
1. Overview
This lab is intended to make you comfortable enough with the Hugs environment (= Haskell + Hugs + E
Lab 9: More On Higherorder Functions
1. Functions as Firstclass Values
CIS 252 h Intro. to Computer Science
In Haskell, functions are firstclass values. This means that they have the
same status as
Lab 8: Higherorder Patterns for Processing Lists
Overview This lab will give you some practice with Haskells higherorder functions map and filter. These generalize some idioms for list
processing tha
Lab 7: Unix Pipes and Filters
Introduction
This is partially based on Chapter 5 of Learning the Unix Operating System by J. Peek, G. Todino, and J. Strang (OReilly 2002). The following
assumes that yo
Lab 4: Haskell List Comprehensions
Overview. In this lab you get to try out some of Haskells basic mechanisms for defining lists. It is based on 5.4 and 5.5 of Thompson. You may work singly or in pair
Name:
CIS 252 Introduction to Computer Science
Exam 1
February 28, 2012
Question
Points
Possible
1
28
2
8
3
16
4
12
5
12
6
12
7
12
Total
Points
Received
100
Instructions:
1. This exam is a closedbook
CIS 252: Exam 2 Sample Solutions
Spring 2012
1. (30 points) Suppose that the following denitions are made:
import Data.Char
data Mystery = Puzzle Char
 Enigma Int Mystery
one : (a,b) > (b,Char)
one
Pop Quiz 1: Sample Solutions
CIS 252 Intro to Computer Science
Name:
Points: 1 2 3
Suppose the following Haskell code is loaded into the Haskell
interpreter (i.e., Ghci):
muddle : Int > Int > Int
mu
Pop Quiz 1
CIS 252 Intro to Computer Science
Name:
Points: 1 2 3
Suppose the following Haskell code is loaded into the Haskell
interpreter (i.e., Ghci):
muddle : Int > Int > Int
muddle
muddle
muddle
Pop Quiz 3: Sample Solutions
CIS 252 Intro to Computer Science
Name:
Points: 1 2 3
Consider the following Haskell denitions:
data Thing = Zero
 One [Int]
 Two Char Bool
item, gizmo : Thing
item = On
Myriad Aspects of Computer Science
1
Componentbased problem solving
Building solutions to complex problems by glueing together
solutions to smaller problems
2
Data structures and operations on them
s
Recap: IO Actions
IO types:
For each Haskell type t, there is a type IO t whose values are:
I/O actions (or programs) that yield a result of type t.
More Haskell I/O
When an I/O action is executed, it
module BinaryTrees where


 The following definition does the following:

 (1) Creates a family of datatypes of the form BTree a
 Examples: BTree Int, BTree Bool, BTree [Float], etc.

 (2) Cre
between 6 7 9  should be False
between 7 6 9  should be True
between 7 9 6  should be False
between 100 (1) 5000  should be True
between 100 100 5000  should be False
xor False False  should be
squarePairs : Int > Integer > [(Integer,Integer)]
squarePairs n i
n<=0 =[]
otherwise = (i,i*i):squarePairs (n1) (i+1)
countDownBy : Int > Int > Int > [Int]
countDownBy m n diff
m<n =[]
o
locate : Eq a => a > [a] > [Int]
locate x ys = map fst ( filter (\(a,b) > b=x) ( zip [1.] ys )
histogram : [Int] > String
histogram xs = concat ( map f xs )
where
f : Int > String
f x = replic
import Turing

 finddggd
 Takes a string containing ds and gs and provide a unary count (as a series
 of 1s) of the number of times the sequence dggd appears in that string.

 Initially, the tap
Another Look at Formal Parameters
Recall from long ago:
simple : Int > Int > Int
simple a b = a + 3*b
Patterns and Tuples and Lists (Oh, My!)
In the definition above, a and b are the formal paramete
Our Haskell Experience to Date: Pure Functions
Weve seen pure functions:
Behavior of a function depends only on its arguments
For example: foo "abc" will always return the same result.
I/O in Haskell
Trees: An Ubiquitous Data Structure in Computing
Basic idea:
Tree
A tree is a collection of linked nodes such that:
1
An Introduction to Trees
2
Not a tree
Prof. Susan Older
There are no cycles: there
Dej`a Vu: Doubling Each Element of a List
Multiply every element of a list by 2:
doubleAll : [Int] > [Int]
An Introduction to HigherOrder Functions
 by recursion
doubleAll [] = []
doubleAll (x:xs)
Turing Machines: A Little History
1928: David Hilbert poses the Entscheidungsproblem.
Is there an eective method (i.e., an algorithm or mechanical procedure)
that, when given an arbitrary statement in