* cis194 Brent Yorgey BFPG talks based n Yorgey course
Speaker: Nick Partridge Video: http://vimeo.com/90515452 Homework 2: [error.log, sample.log, Log.hs ]
Speaker: Matthew Brecknell Video: http://vimeo.com/92976563 Homework 3:
Speaker: Christopher McKay Video: http://vimeo.com/97015597 Homework 4:
Speaker: Fraser Tweedale Video: http://vimeo.com/99034519 Homework 5: [ExprT.hs, Parser.hs, StackVM.hs ]
Speaker: Ben Kolera Video: http://vimeo.com/101396464 Homework 6:
Speaker: George Wilson github George Wilson Video: http://vimeo.com/105047461 Slides: https://github.com/gwils/bfpg-slides-140826 Homework 7: [Editor.hs, Buffer.hs, Sized.hs, StringBuffer.hs, StringBufEditor.hs, carol.txt ]
Speaker: Jamie Cook Video: http://vimeo.com/107081622 Homework 8: [Employee.hs, company.txt ]
Speaker: Brenton Alker Video: http://vimeo.com/110492903 Homework 9: due never (no HW this week).
Speaker: Sean Chalmers (week 10 & 11) Video: http://vimeo.com/112814183 Homework 10: [AParser.hs ]
Speaker: Sean Chalmers (week 10 & 11) Video: http://vimeo.com/112814183 Homework 11: [AParser.hs, SExpr.hs ]
Speaker: Matt Peddie Video: http://talks.bfpg.org/talks/2015-02-24.monads.html Homework 12: [Risk.hs ]
1. Introduction to Haskell - BFPG talk based on BYorgey course Haskell is lazy, functional language. Haskell is- Functional
- functions are first-class
- evaluating expressions rather than executing instructions.
- Pure
- Haskell expression are always referentially transparent
- No mutations! Everything is immutable
- No side effcts.
- same input -> same output allways
- Purity mean also
- Equational reasoning and refactoring: In Haskell one can always “replace equals by equals”, just like you learned in algebra class.
- Parallelism: Evaluating expressions in parallel is easy when they are guaranteed not to affect one another.
- Fewer headaches: Simply put, unrestricted effects and action-at-a-distance makes for programs that are hard to debug, maintain, and reason about.
- Haskell expression are always referentially transparent
- Lazy
expressions are not evaluated until their results are actually needed
- It is easy to define a new control structure just by defining a function.
- It is possible to define and work with infinite data structures.
- It enables a more compositional programming style (see wholemeal programming below).
- One major downside, however, is that reasoning about time and space usage becomes much more complicated!
- Statically typed
Difference lists video from author
file:../../CIS194/reisenberg/homework/haskell/src/Hw02.hs::— Exercise 7.Week 3: Algebraic data types
- Algebraic data types in general In general, an algebraic data type has one or more data constructors, and each data constructor can have zero or more arguments.
data AlgDataType = Constr1 Type11 Type12
| Constr2 Type21 |
| Constr3 Type31 Type32 Type33 |
| Constr4 |
type and data constructor names must always start with a capital letter
- Pattern Matching pattern-matching is about taking apart a value by finding out which constructor it was built with. This information can be used as the basis for deciding what to do—indeed, in Haskell, this is the only way to make a decision.
In general, the following grammar defines what can be used as a pattern:
pat ::= _
| var |
| var @ ( pat ) |
| ( Constructor pat1 pat2 … patn ) |
Note that literal values like 2 or ‘c’ can be thought of as constructors with no arguments. It is as if the types Int and Char were defined like
data Int = 0 | 1 | -1 | 2 | -2 | … data Char = ‘a’ | ‘b’ | ‘c’ | …
which means that we can pattern-match against literal values. (Of course, Int and Char are not actually defined this way.)
- Case expressions case exp of pat1 -> exp1 pat2 -> exp2 …
- First-class functions
- Recursive data types
Data types can be recursive, that is, defined in terms of themselves. data IntList = Empty | Cons Int IntList data Tree = Leaf Char
| Node Tree Int Tree |
deriving Show
4. Higher-order programming and type inference - BFPG talk based on BYorgey courseHomework 4: Binary search trees
▶Two different forms of polymorfism (1). parametric polymorphism, which we can also call universal polymorphism A function like length :: [a] -> Int works for any type a.
(2).ad-hoc polymorphism - But, sometimes we don’t want to be universal. Sometimes, we want a function to work for several types, but not every type. A great example of this is (+). We want to be able to add Ints and Integers and Doubles, but not Maybe Chars. • This sort of polymorphism – where multiple types are allowed, but not every type – is called ad-hoc polymorphism. Haskell uses type classes to implement ad-hoc polymorphism. A Haskell type class defines a set of operations. We can then choose several types that support those operations via class instances. (Note: These are not the same as object-oriented classes and instances!) Intuitively, type classes correspond to sets of types which have certain operations defined for them.
▶derivable classes This deriving mechanism is baked into Haskell – you can’t make your own class and tell GHC how to derive instances. GHC does provide extensions that allow other classes to be derived; see the GHC manual for details.
- Eq
- Ord
- Enu
- Ix
- Bounded
- Show
- Read
▶pattern guards parse str
| Just rest <- stripPrefix “True” str = Just (True, rest) |
| Just rest <- stripPrefix “False” str = Just (False, rest) |
| otherwise = Nothing |
Week 6 (2 October): Monoids, I/O
BFPG video 00-14min - seen 14-30min -