Skip to content

Instantly share code, notes, and snippets.

@kanak
kanak / Bird02.lhs
Created March 26, 2011 00:19
Bird's Introduction to Functional Programming: Chapter 02 Simple Datatypes Notes and Solutions
Richard Bird - Introduction to Functional Programming using Haskell [2ed]
Chapter 02: Simple Datatypes
> module Bird02 where
> import Data.Char (chr, ord)
================================================================================
2.1 Booleans
> data Bool' = False' | True'
@kanak
kanak / Bird01.lhs
Created March 25, 2011 20:35
Bird's Introduction to Functional Programming: Chapter 01 Fundamental Concepts Notes and Solutions
Richard Bird - Introduction to Functional Programming using Haskell [2ed]
Chapter 01: Fundamental Concepts
> module Bird01 where
> import Prelude hiding (pi, signum, abs)
================================================================================
1.1 Sessions and Scripts
Some definitions from the book. I've used more general type signatures.
@kanak
kanak / DiscreteMathComputer13.hs
Created March 24, 2011 21:45
Discrete Mathematics Using a Computer Chapter 13: Circuit Simulation
{- Discrete Mathematics Using a Computer
Chapter 13: Circuit Simulation
Story: verify circuit properties using math because actually building and
testing is expensive.
-}
module Main where
import Data.List (intersperse)
-- Signal is anything that can be manipulated by circuits
@kanak
kanak / DiscreteMathComputer12.hs
Created March 24, 2011 21:20
Discrete Mathematics Using a Computer Chapter 12: AVL Tree Notes and Solutions
{- Discrete Mathematics Using a Computer
Chapter 12: AVL Trees
AVL Trees: Self-balancing binary trees.
-}
module AVL where
data SearchTree k d = Leaf
| Node k d (SearchTree k d) (SearchTree k d)
deriving (Show)
@kanak
kanak / DiscreteMathComputer10.hs
Created March 22, 2011 04:01
Discrete Mathematics Using a Computer Chapter 11: Functions Notes and Solutions
{- Discrete Mathematics Using a Computer
Chapter 11: Functions
-}
module Functions where
import Data.Tuple (swap)
-- =============================================================================
-- 11.1 The Graph of a Function
@kanak
kanak / DiscreteMathComputer10.hs
Created March 20, 2011 04:51
Discrete Mathematics Using a Computer Chapter 10: Relations Notes and Solutions
{- Discrete Mathematics Using a Computer
Chapter 10: Relations
-}
module Relations where
import List (nub)
import Stdm (setEq, union, isWeakest, isGreatest, isQuasiOrder, isLinearOrder)
import Data.Tuple (swap)
-- =============================================================================
@kanak
kanak / DiscreteMathComputer09.hs
Created March 18, 2011 01:55
Discrete Mathematics Using a Computer Chapter 09: Inductively Defined Sets Solutions
{- Discrete Mathematics Using a Computer
Chapter 09: Inductively Defined Sets
-}
module IndSet where
-- =============================================================================
-- 9.1: The Idea Behind Induction
{- Suppose we have know that:
@kanak
kanak / DiscreteMathComputer08.hs
Created March 17, 2011 22:44
Discrete Mathematics Using a Computer Chapter 08: Sets Solutions
{- Discrete Mathematics Using a Computer
Chapter 08: Sets
-}
module Sets where
type Set a = [a]
-- Note, this definition prevents us from having heterogeneous sets
-- TODO: use hlist (http://homepages.cwi.nl/~ralf/HList/) ?
@kanak
kanak / DiscreteMathComputer07.txt
Created March 17, 2011 19:31
Discrete Math Using a Computer: Chapter 7 Review Exercises Solutions
#+TITLE: DiscreteMathComputer 07-Predicate Logic
#+DATE:
#+LATEX_HEADER: \usepackage{fullpage}
#+OPTIONS: H:3 toc:nil
* Introduction: Why Predicates Logic
- Want to make the statement that everything has a certain property
+ e.g. "All men are mortal"
- Propositional Logic doesn't provide us any structure to express this
+ e.g. could say "P = all men are mortal"
@kanak
kanak / DiscreteMathComputer06-Review.hs
Created March 17, 2011 03:40
Discrete Math Using a Computer: Chapter 6 Review Exercises Solutions
{- Discrete Math Using a Computer
Chapter 6: Propositional Logic
Review Exercise
-}
import Stdm
--------------------------------------------------------------------------------
-- Exercise 34: Prove A ^ ~A |- False