McMaster University - CAS 743
Winter 2006
Dr. Wolfram Kahl,
ITB-245 , ext: 27042,
kahl@mcmaster.ca.
The course outline is available as
PostScript
and as
PDF
.
(4-up on Letter paper --- printing on A4 paper will cut off a part.)
WC.hs,
Cat.hs,
Usrs.hs
case,
let, where, list functions (January 23):
Eq, Ord;
type of members, default definitions,
instances, class invariants (contracts),
deriving, superclasses
data declarations
Show class,
the cost of conversion between show :: a -> String
and shows :: a -> ShowS
Either and Maybe,
binary tree type Tree,
primitive recursion
(either, maybe, foldTree);
recod syntax.
Show instance for Tree:
linear complexity with ShowS composition,
quadratic complexity with String concatenation.
HTree
for Huffman trees, and the decoding function
decode :: HTree a -> [Bool] -> [a]
(Additional exercise: Define
encode :: Eq a => [a] -> (HTree a, [Bool])
such that uncurry decode . encode = id
and the generated code string is as short as possible.)
Data.Monoid.Monoid,
monoid laws, monoid homomorphisms.
Functor;
kinds as ``types for the type language''.
instance Functor Maybe ... instance Functor (Either c) ... instance Functor ((,) c) ... instance Functor ((->) c) ... instance Functor Tree ... instance Functor HTree ... newtype K c a = K c instance Functor (K c) ... newtype Plus f g a = MkPlus (Either (f a) (g a)) instance Functor (Plus f g) ...
data Functor1 f where fmap1 :: (a -> b) -> f a c -> f b c instance Functor1 Either ... instance Functor1 (,) ... instance Functor1 (->) ...
data example:
data T a = T a [T a]Exercise:
Functor instance!
data L a = E | C Bool a instance Functor L where ... -- completed and verified in classstarting from the initial object of the Haskell category
data Empty -- contains undefined as only elementand (skipped in class) the morphisms
injectL0 :: Empty -> L Empty injectL0 _ = undefined -- the unique morphism from the initial object injectL1 :: L Empty -> L (L Empty) injectL1 = fmap injectL0 injectL2 :: L (L Empty) -> L (L (L Empty)) injectL2 = fmap injectL1 ...The colimit of this chain is the semantics of the recursive datatype
[ Bool ] = L [ Bool ].
The colimit contains all finite and inifinite lists - it has to contain infinite lists, too, to be a CPO.
data declarations
can be annotated as strict be prefixing the argument types with
a ``!''.
To keep the drawings of the chain CPOs smaller,
I really used
data L' a = E | C !Bool ain class; there,
C is strict in the first argument.
Strictness annotations can be useful for efficiency considerations.
class Monad
class Read
class Monad including fail
newtype, and review of sets-implemented-as-lists
abstract export example
class MonadPlus (and Haskell-1.3 class MonadZero)
StateMachine_skel.hs
For literate Haskell modules typeset in LaTeX, there are two options:
code environments using
verbatim, for example by using
code.sty with
\usepackage{code}
oz.sty - documentation:
``Academic dishonesty consists of misrepresentation by deception or by other fraudulent means and can result in serious consequences, e.g. the grade of zero on an assignment, loss of credit with a notation on the transcript (notation reads: ``Grade of F assigned for academic dishonesty''), and/or suspension or expulsion from the university.
It is your responsibility to understand what constitutes academic dishonesty. For information on the various kinds of academic dishonesty please refer to the Academic Integrity Policy, specifically Appendix 3, located at http://www.mcmaster.ca/senate/academic/ac_integrity.htm
The following illustrates only three forms of academic dishonesty:
``The Faculty of Engineering is concerned with ensuring an environment that is free of all adverse discrimination. If there is a problem that cannot be resolved by discussion among the persons concerned, individuals are reminded that they should contact the Department Chair, the Sexual Harassment Office or the Human Rights Consultant, as soon as possible.''
(