\input{haskpres.cfg}
\documentstyle{fppres}
\title{Programming in the Style of Mathematics}
\begin{document}
\begin{presentation}
{Programming in the Style of Mathematics}
{Fritz Ruehr}{1}{14 November 2002}{}
\begin{slide}{Introduction}
\slideitem{Traditional computing: not the best tool for math}
traditional finite representations do not respect mathematical accounts of numbers:
\par\dot when integers grow "too large" they can become negative
\par\dot floating point values represent real numbers inaccurately
\break (see Prof. Janeba's Numerical Analysis course)
\slideitem{Computing: more than just a tool for {\it doing} math}
computing can have a better relationship with math:
\par\dot computational style can reflect math sensibilities
\par\dot computation can be studied from a mathematical perspective
\slideitem{What are "mathematical sensibilities"?}
\par\dot proof, equational reasoning
\par\dot concise, stylized language
\par\dot what, not how (i.e., results, not process)
\par\dot focus on relevance, suppress distractions
\par\dot abstraction and generality
\par\dot conceptual elegance (e.g., symmetry, duality)
\slideitem{Functional programming}
an alternative style (or "paradigm"), outside the mainstream, which stresses sound mathematical semantics and encourages formal methods
\slideitem{The Haskell programming language}
a {\it purely} functional language with a math-friendly syntax and a sophisticated, flexible type system
\break {\it (other functional languages: Clean, SML, Caml, Scheme, LISP, APL, ...)}
\end{slide}
\begin{slide}{A Quick Taste of Haskell (I)}
\slideitem{An introduction to Haskell through examples}
we give the flavor of Haskell via examples in the Hugs interactive interpreter
\break {\it (in the talk itself, we hope to run these examples "live")}
\slideitem{Simple arithmetic, large integers}
simple calculation can be done at the interactive prompt
\haskon\begin{code}> 2 + 3 * 5
17
> 37^37
10555134955777783414078330085995832946127396083370199442517\end{code}\haskoff
\slideitem{Exact rational arithmetic}
Haskell provides exact rational numbers (written with an infix "\%") as a safer alternative to floating-point
\haskon\begin{code}> 51 % 3
17 % 1
> (51 % 3) * (2 % 5)
34 % 5\end{code}\haskoff
\slideitem{Floating-point arithmetic}
Traditional IEEE floating-point arithmetic is also available (with the usual caveats)
\haskon\begin{code}> 2.3 ^ 5
64.36343
> $$ * 25.333
1630.51877\end{code}\haskoff
\slideitem{Pairs and tuples}
Unlike most languages, Haskell provides pairs and tuples as independent entities (e.g., to return multiple results)
\haskon\begin{code}> 17 `divMod` 3
(5,2)
> 17 `divMod` 3
(5,2)\end{code}\haskoff
\slideitem{Lists of numbers (ellipsis notation)}
we can easily generate and manipulate lists of numbers
\haskon\begin{code}> [1..12]
[1,2,3,4,5,6,7,8,9,10,11,12]
> sum [1..10]
55
> product [1..10]
3628800\end{code}\haskoff
\slideitem{Z-F expressions}
another notational convenience (due to David Turner) is {\bf list comprehension}, which mimics notation from Zermelo-Fraenkel set theory
\haskon\begin{code}> [ a * b | a<-[1..3], b<-reverse [1..4] ]
[4,3,2,1,8,6,4,2,12,9,6,3]
> [ 2^i | i<-[1..20], odd i]
[2,8,32,128,512,2048,8192,32768,131072,524288]\end{code}\haskoff
\slideitem{Strings and list operations}
\haskon\begin{code}> replicate 3 "hello"
["hello","hello","hello"]
> words "This is a sample text"
["This","is","a","sample","text"]
> unwords (reverse $$)
"text sample a is This"\end{code}\haskoff
\end{slide}
\begin{slide}{A Quick Taste of Haskell (II)}
\slideitem{Booleans and {\tt if} expressions}
The usual boolean values are written with initial caps; the conditional construct is an {\it expression}, not a {\it statement}
\haskon\begin{code}> if 3 < 2 then "oops" else "hurray!"
"hurray!"
> (if 3 < 2 then (+) else (*)) 10 20
200\end{code}\haskoff
\slideitem{Infinite lists and lazy evaluation}
Haskell provides {\bf lazy evaluation} for functions and data structures, so we can define infinite lists (it is prudent to avoid evaluation of a whole infinite list!)
\haskon\begin{code}> [1,3..]
[1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,{Interrupted!}
> take 20 [1,3..]
[1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39]\end{code}\haskoff
\slideitem{Higher-order functions }
Haskell allows functions to take other functions as arguments, or to return functions as results
\haskon\begin{code}> even 3
False
> any even [1,3..11]
False
> any (>10) [1..]
True\end{code}\haskoff
\slideitem{Currying}
Haskell functions of several arguments are actually "curried", i.e., they are higher-order functions of successive arguments
\haskon\begin{code}> 2 + 3
5
> (+) 2 3
5
> :t (+)
(+) :: Num a => a -> a -> a
> :t (2+)
(2 +) :: Num a => a -> a\end{code}\haskoff
\slideitem{The map functional}
The map functional takes a function as its first argument, then applies it to every element of a list
\haskon\begin{code}> map (^2) [1..10]
[1,4,9,16,25,36,49,64,81,100]
> map (`div` 3) [1..20]
[0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6]
> map reverse ["hey", "there", "world"]
["yeh","ereht","dlrow"]\end{code}\haskoff
\slideitem{The fold functions}
The fold functions {\tt foldl} and {\tt foldr} combine elements of a list based on a binary function and an initial value
\haskon\begin{code}> foldr (+) 0 [1..10]
55
> sum [1..10]
55
> foldr (*) 1 [1..5] == 1 * 2 * 3 * 4 * 5 * 1
True
> foldr (++) [] ["a", "bb", "ccc"]
"abbccc"\end{code}\haskoff
\slideitem{Strong, static typing}
expressions in Haskell are only well-formed if they are {\bf well-typed} according to a sophisticated type system
\haskon\begin{code}> :t ['a'..'z']
enumFromTo 'a' 'z' :: [Char]
> :t reverse
reverse :: [a] -> [a]
> :t foldr
foldr :: (a -> b -> b) -> b -> [a] -> b
> :t foldr (++) []
foldr (++) [] :: [[a]] -> [a]\end{code}\haskoff
\slideitem{More examples of Haskell in actions}
here are some links to external files defining Haskell types and functions
\par\dot \par \xlink{http://www.willamette.edu/~fruehr/haskell/code/short.txt}{short, simple examples}
\par\dot \par \xlink{http://www.willamette.edu/~fruehr/haskell/code/MathEgs.txt}{some math-oriented examples from the Hugs distibution}
\par\dot \par \xlink{http://www.willamette.edu/~fruehr/haskell/code/Lattice.txt}{type classes used to capture lattices abstractly (from the Hugs distibution)}
\par\dot \par \xlink{http://www.willamette.edu/~fruehr/haskell/code/GenSort.txt}{a generic sorting application applied to a simple database}
\par\dot \par \xlink{http://www.willamette.edu/~fruehr/haskell/code/expr.txt}{a flexible system for parsing and processing arithmetic expressions}
\end{slide}
\begin{slide}{The Mathematical Style of Haskell}
\slideitem{Programming paradigms}
functional programming is just one of several major {\it programming paradigms}
\par \xlink{http://www.willamette.edu/~fruehr/haskell/lectures/paradigms.html}{(see diagram here)}
\slideitem{History of functional programming}
functional proramming properly begins with LISP and APL in the 1950's and 1960's
\break (but it got a big boost in the late 70's with Backus' Turing Award)
\slideitem{History of Haskell}
Haskell was a community effort (open source) in reaction to proprietary Miranda
("Miranda" is a trademark of Research Software, Ltd.")
\slideitem{Haskell fits well with mathematical style and usage}
many features collaborate to support this fit
based on mathematical concepts (functions, algebra)
\par\dot higher-order functions, algebra = structure + operations
concise, high-level descriptions
\par\dot whole-structure manipulation
referential transparency (allows equational reasoning)
\par\dot no aliasing, no time-bound effects
well-behaved numeric types
\par\dot big integers and exact rationals
\slideitem{an uncluttered, math-compatible syntax}
infix operators, ZF-expressions, guards, let declarations
\haskon\begin{code}2+3*4
[ x^2 | x <- [1..10] ]
abs x | (x < 0 ) = -x
| otherwise = x
let x = 3*y+7 in x^2-k\end{code}\haskoff
\slideitem{Haskell has been guided by a consistent, {\it persistent} design philosophy}
the community has held its ground against encroachment by "impure" features
this discipline has actually led to major innovations (e.g., monads)
\end{slide}
\begin{slide}{Technical Aspects of the Haskell Language}
\slideitem{Programs are sets of equational definitions}
equational (or conditional-equational) substitution is vital to formal methods
\slideitem{Based on lambda calculus and combinators}
these theories of pure functions inspire higher-order functions and lazy evaluation
\slideitem{Data structure definitions are (roughly) initial algebras}
they also look like context-free grammars, thus encouraging embedded languages
\slideitem{Strong, static type system provides security and flexibility}
Hindley-Milner polymorphism allows convenient inference of types
\slideitem{Type classes provide for representation independence and data abstraction}
we can capture the abstract essence of a component without requiring a specific implementation
\slideitem{Types as high-level sketches of structure}
Haskell increasingly supports type-level features, encouraging high-level "programming-in-the-large"
\end{slide}
\begin{slide}{Haskell Applications (I)}
\slideitem{Fran: Functional Reactive Animation}
Conal Elliot and Paul Hudak have developed sophisticated graphics, animation and interaction techniques
\par \xlink{http://www.conal.net/fran/tutorial.htm}{Elliot's FRAN tutorial}
\par \xlink{http://haskell.cs.yale.edu/soe/demos.htm}{Hudak's SOE demo page at Yale}
\slideitem{Functional imagery}
Conal and Jerzy Karczmarczuk have explored images as functions from points to colors
\par \xlink{http://conal.net/papers/functional-images/jfp/figures.html}{Conal's Functional Images gallery}
\par \xlink{http://users.info.unicaen.fr/~karczma/arpap/texturf.pdf}{Jerzy's texture page}
\slideitem{Haskore: based on an algebra of music}
Paul Hudak at Yale is also a jazz musician: he has developed an abstract language for music based on pitches, tempos, transpositions and sequential and parallel composition
\par \xlink{http://haskell.org/haskore/onlinetutorial/haskore.html}{the on-line documentation for Haskore}
\slideitem{Haskell in K-12 education}
a group at Yale led by Hudak and John Peterson is exploring the use of these ideas for mathematics-based K-12 education
\par \xlink{http://www.haskell.org/edsl/math.htm}{introduction and sample student work}
\end{slide}
\begin{slide}{Haskell Applications (II)}
\slideitem{Lula: based on an algebra of theatre lighting}
Michael Sperber at Universitat Tubingen has developed a successful theatre lighting program based on abstract notions of cues, fixtures, intensities, pan/tilt, etc.
\par \xlink{http://www-pu.informatik.uni-tuebingen.de/users/sperber/papers/developing-stage-lighting-system.pdf}{a paper describing Lula and its algebra}
\slideitem{An algebra of financial contracts}
Peyton Jones, Eber and Seward have developed an award-winning, abstract approach to specifying financial contracts based on abstract notions of time, choice, obligation and currency
\par \xlink{http://research.microsoft.com/~simonpj/papers/Options-ICFP.ppt}{a PowerPoint presentation on the contract system}
\slideitem{The Vital visualization tool for Haskell}
Keith Hammond at the University of Kent at Canterbury has developed a spreadsheet-like interface for visualizing Haskell data
\par \xlink{http://www.cs.ukc.ac.uk/people/staff/fkh/Vital/overview/overview.html}{an on-line overview of Vital}
\slideitem{The Alfa proof editor}
a group at Chalmers University in Sweden has developed an interactive proof editor in Haskell
\par \xlink{http://www.math.chalmers.se/~hallgren/Alfa/Tutorial/ndstyle.html}{a quick overview of Alfa}
\slideitem{Haskell-based hardware simulation (NSW, Ruby, Hawk) }
a number of different groups around the world have used Haskell and other functional languages to model hardware (chips) and perform logic-based validation
\end{slide}
\begin{slide}{Haskell Opportunities at Home and Abroad}
\slideitem{Functional Programming, CS 454}
I teach a one-semester course in functional programming (using Haskell) every two years at Willamette
\par (offered in Spring of 2003 on MWF 10:20-11:20, lab MW 3:00-4:30)
\slideitem{A gateway to the mathematics of programming}
\par\dot study of functional programming opens up the door to a variety of mathematical topics in Computer Science:
\par\dot alternative foundations for computability (lambda calculus)
\par\dot denotational semantics (formal meanings for programs via fixed-points)
\par\dot type theory and intutionistic logic (a "typed set theory" with a constructive flavor)
\par\dot category theory (an abstract approach to algebra treating structure generically)
\slideitem{PacSoft Research at the Oregon Graduate Institute}
a world-renowned research group at OGI focuses on functional programming, formal methods and Haskell
\par \xlink{http://www.cse.ogi.edu/PacSoft/}{the PacSoft home page}
\par (I sometimes also attend a Tuesday morning research seminar there)
\slideitem{Galois Connections, Inc.}
a faculty-led spin-off company uses Haskell and other formal methods tools to develop secure software solutions for clients such as the National Security Agency
\par \xlink{http://galois.com/}{the Galois Connections home page}
\slideitem{Opportunities for Graduate Study}
many top-flight graduate schools have programs and projects based on functional programming and related ideas
\par US schools: OGI, OSU, Yale, Indiana, Stanford, Carnegie Mellon, MIT, University of Washington, UC Berkeley, and many others
\par international schools: Oxford, Glasgow, Chalmers, Nottingham, Kent, York, Edinburgh, Utrecht, Glasgow, INRIA (France), New South Wales, and others
\end{slide}\nl
\end{presentation}
\end{document}