Skip to content
CSCI 3137: Haskell Programming
An Example
Initializing search
CSCI 3137: Haskell Programming
Introduction
Introduction
Conventions
Functional Programming
Functional Programming
Simple Functions
Function Composition
Case Distinctions
When to Program Functionally
First Steps in Haskell
First Steps in Haskell
The Tools You Need
GHC, GHCI & Stack
Customizing the GHCi Prompt (Optional)
Hoogle
Basic Haskell Syntax
Basic Haskell Syntax
Names
Reserved Words and Symbols
Code Blocks and Indentation
Functions
Basic Types and Operators
Basic Types and Operators
Numbers
Numbers
Integer Types
Floating Point Types
Explicit Conversion
Other Number Types
Booleans
Characters and Strings
Type Signatures
Functions Types
Functions Types
Anonymous Functions
Multi-Argument Functions
Currying
Function Composition
Function Application
Using GHCi
Using GHCi
Starting and Stopping
Evaluating Expressions
Defining Values and Functions
Loading Modules and Files
Information About Definitions
Information About Definitions
Type Queries
More Comprehensive Information
Code Listing
The Contents of a Module
Case Distinctions
Case Distinctions
If-Then-Else
Case
Pattern Matching
Pattern Guards
Local Definitions
Local Definitions
Let
Where
Nested Scopes
Repeating Things: Recursion
Repeating Things: Recursion
Tail Recursion
Mini-Project: Fibonacci Numbers
Data Types
Data Types
Data
Data
Enumerations
Product Types
Unions of Product Types
Recursive Types
Parameterized Types
Parameterized Types
Maybe
Lists
Haskell Lists
Records (Structs)
Newtype
Type Aliases
Laziness
Laziness
Short Circuit Evaluation For Free
Conditional Evaluation of Expressions
Weak Head Normal Form
Thunks
Infinite Data Structures
Mini-Project: Fibonacci Numbers Revisited
Tuples, Lists, and Arrays
Tuples, Lists, and Arrays
Tuples
List Functions
List Functions
(:), (++), and concat
head and tail
null and length
map
filter and find
zip, zipWith, and unzip
foldl and foldr
unfoldr
Mini-Project: The List of All Prime Numbers
List Comprehensions
List Comprehensions
Range Comprehensions
map as a List Comprehension
Nested Iteration
filter as a List Comprehension
zip and zipWith as a List Comprehension
Arrays and Array Functions
Arrays and Array Functions
The Array Type
Building Arrays and Reading Array Elements
Conversion to a List
Arrays as Accumulators
Bulk Updates
Mutable Arrays
Mini-Project: Permuting a Sequence
Mini-Project: Counting Sort
Mini-Project: Longest Common Subsequence
Controlling Polymorphism Using Type Classes
Controlling Polymorphism Using Type Classes
Type Classes
Defining Type Classes and Instances
Type Constraints as Contracts
Default Function Implementations
Subclasses
Standard Type Classes
Standard Type Classes
Eq
Ord
Num
Fractional
Integral
Real
Enum
Show
Read
Ix
Our Own Type Classes
Deriving Instances Automatically
Type Families
Well-Behaved Containers: Functors and Folds
Well-Behaved Containers: Functors and Folds
Functors
Functors
Functor Laws
Lists
Maybe
Identity
Trees
Reader
Reader
The Connection Between Functions and Containers
More Functions for Functors
Interlude: Monoids
Folds
Folds
The Foldable Class
The Foldable Class
foldl
foldr
foldMap
fold
foldMap'
foldl' and foldr'
foldl1 and foldr1
toList
null and length
elem
minimum and maximum
sum and product
Lists
Maybe
Identity
Trees
Non-Foldable Containers
More Functions for Foldable Containers
More Functions for Foldable Containers
concat
concatMap
and and or
all and any
find
Pure Representations of Effectful Computations: Monads
Pure Representations of Effectful Computations: Monads
A Motivating Example
Monads
Maybe: Simple Exception Handling
Maybe: Simple Exception Handling
Representing Failure
Maybe as a Monad
Catching Exceptions
Do Notation
Do Notation
Desugaring Do
Either: Exception Handling with Error Information
Lists: Non-Determinism
Lists: Non-Determinism
Exploring a Maze
List Comprehensions Revisited
Reader: Computing with Context
Writer: Producing a Log
State: Stateful Computations
Monadic List Functions
Monadic List Functions
mapM
filterM
zipWithM
foldM
sequence
Sequencing Actions for Their Effects
IO: Talking to the Outside World
IO: Talking to the Outside World
Reading from stdin and Writing to stdout
Reading and Writing Files
Lazy I/O
Better Text Support
Reading and Writing Binary Data
Monad Transformers
Monad Transformers
Standard Transformers
Standard Transformers
ReaderT
ReaderT
Reader
An Example
MaybeT
MaybeT
Maybe
An Example
WriterT
StateT
StateT
An Example
Reader-Writer-State
The MonadTrans Class
MonadState, MonadReader, MonadWriter, MonadIO
MonadState, MonadReader, MonadWriter, MonadIO
Instances for ReaderT, WriterT, and StateT
Derived Instances
MonadIO
An Example
Continuations
Continuations
Continuations in Scheme
Continuations in Scheme
Exception Handling
Loops
Coroutines
Continuations in Haskell
Continuations in Haskell
Loops
Exception Handling: First Try
Continuation Passing Style
Exception Handling: For Real Now
Coroutines
The Cont Monad
The Cont Monad
callCC
Exceptions
Coroutines
Loops
One Monad to Rule Them All
One Monad to Rule Them All
Maybe via Cont
State via Cont
Reader and Writer via Cont
The List Monad via Cont
Modules, Packages, and Building Complete Programs
Modules, Packages, and Building Complete Programs
Modules
Export Lists
Export Lists
Restricting Exports
Exporting Opaque and Transparent Types
Opaque Exports of Record Types
Re-Exports
Re-Exporting Whole Modules
Importing Modules
Importing Modules
Import Lists
Qualified Imports
Module Aliases
Hiding Imports
Packages and Stack Projects
Packages and Stack Projects
Creating a New Stack Project
stack.yaml
package.yaml
Building a Stack Project
Running a Stack Project
Installing a Stack Project
Cleaning a Stack Project
Project: Navigating a Maze
Project: Navigating a Maze
Project: k-Means Clustering
Project: k-Means Clustering
Project: A Tree Parser
Project: A Tree Parser
None
Conclusions
An Example
Coming soon!