Created
April 22, 2015 11:28
-
-
Save denibertovic/2372c3b7e822e93864cb to your computer and use it in GitHub Desktop.
Lambda Zagreb Meetup: Haskell overview slides (Markdown)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Haskell Overview | |
--- | |
## About me | |
__Deni Bertovic__ | |
_I blog sometimes:_ | |
https://denibertovic.com | |
_And I run a small consultancy:_ | |
https://initeq.net | |
--- | |
## What this presentation was supposed to be about | |
A comprehensive overview of Haskell (with examples) | |
--- | |
## What this presentation is actually about | |
Ideas for future talks (we need speakers!) | |
--- | |
## Haskell | |
"A language that everybody talks about but nobody uses." | |
\- SPJ | |
--- | |
## Features | |
- Purely functional (immutable values) | |
- Controling effects (Mondas) | |
- Lazyness | |
- Concurrency/Prallelism | |
- (E)DSLs | |
- Types (Say it again! TYPES!) | |
- Growing ecosystem (ie. "There's a library for that") | |
--- | |
## Haskell in one slide | |
Example by SPJ | |
filter :: (a -> Bool) -> [a] -> [a] | |
filter p [] = [] | |
filter p (x:xs) | |
| p x = x : filter p xs | |
| otherwise = filter p xs | |
- type signature optional | |
- higher order | |
- polymorphic | |
- function pattern matching | |
- guards for sub cases | |
- function application is white space | |
--- | |
## More features | |
- lambda, composition, currying, equational reasoning | |
--- | |
## Lambda | |
(\x -> x + 1) 4 | |
-- 5 | |
--- | |
## Composition | |
desort x = (reverse . sort) x | |
--- | |
## Currying (Partial application) | |
max' = (max 4) | |
max' 5 | |
-- prints 5 | |
-- In general this means | |
f x y = something | |
f = \x -> (\y -> something) | |
--- | |
## Equational Reasoning (Referential Transparency) | |
x = 5 | |
-- x is 5 EVERYWHERE (* of course scoping applies) | |
--- | |
## Laziness | |
> let xs = map (+1) [1..10] | |
> :sprint xs | |
-- xs = _ | |
> seq xs () | |
> :sprint xs | |
-- xs = _ : _ | |
> lengt xs | |
> :sprint xs | |
-- xs = [_, _, _, _, _, _, _, _ ,_ ,_ ,_] | |
> sum xs | |
> :sprint xs | |
-- xs = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11] | |
--- | |
## Types | |
-- Sum Types | |
data Bool = True | False | |
-- Product Types | |
data Person = String Int | |
-- Record Syntax | |
data Person = Person { | |
name :: String | |
, age :: Int | |
} deriving (Show) | |
--- | |
## Types why do they matter | |
Example by Bob Ippolito | |
class AST(object): | |
def eval(self): | |
raise NotImplementedError | |
class Constant(AST): | |
def __init__(self, value): | |
self.value = value | |
def eval(self): | |
return self.value | |
class Minus(AST): | |
def __init__(self, node): | |
self.node = node | |
def eval(self): | |
return self.node.eval() | |
class Add(AST): | |
def __init__(self, left, right): | |
self.left = left | |
self.right = right | |
def eval(self): | |
return self.left.eval() + self.right.eval() | |
class Multiply(AST): | |
def __init__(self, left, right): | |
self.left = left | |
self.right = right | |
def eval(self): | |
return self.left.eval() * self.right.eval() | |
--- | |
## ADTs | |
Example by Bob Ippolito | |
```haskell | |
data AST = Constant Int | |
| Add AST AST | |
| Minus AST | |
| Multiply AS AST | |
deriving (Show, Eq) | |
eval :: AST -> Int | |
eval node = case node of | |
Constant n -> n | |
Add ab -> eval a + eval b | |
Minus n -> negate (eval n) | |
Multiply a b -> eval a * eval b | |
``` | |
--- | |
## Type Classes | |
plus :: a -> a -> a | |
-- OR | |
plus :: Num a => a -> a -> a | |
class Num a where | |
(+), (-), (*) :: a -> a -> a | |
negate :: a -> a | |
abs :: a -> a | |
signum :: a -> a | |
fromInteger :: Integer -> a | |
--- | |
## Instances | |
Instance Num Int where | |
-- implements the above methods | |
- Can be added after the fact | |
--- | |
## More type goodness | |
- type | |
- newtype | |
--- | |
## (E)DSLs | |
Interpreter pattern (Teletype) | |
--- | |
## Parell Computing | |
- Powerful abstractions for Parallel computing | |
- Powerful tooling for analytics (ThreadScope) | |
--- | |
## Concurrency | |
- MVar (and and co) | |
- STM | |
- Cloud Haskell | |
--- | |
## Parallel and Concurrent Programming in Haskell | |
by Simon Marlow | |
--- | |
## Cabal | |
The build tool | |
--- | |
## Hackage | |
- Aeson | |
- Wreq | |
- Lens | |
- Pipes | |
- ekg | |
- propellor | |
- Shake | |
- Haddock | |
- Yesod | |
- Snap | |
...And many more | |
--- | |
## Thats all great but the big question is... | |
--- | |
## How can I JavaScript with Haskell? | |
- Purescript (https://leanpub.com/purescript/read) | |
- GHC-JS | |
- ELM | |
- Haste | |
- Fay | |
--- | |
## Game programming | |
Functional Reactive programming (https://leanpub.com/gameinhaskell) | |
--- | |
## And yes it works on Android and iOS | |
--- | |
## More Books | |
[Learn you a Haskell - Miran Lipovaca](http://learnyouahaskell.com/) | |
[Programming in Haskell - Graham Hutton](http://www.cs.nott.ac.uk/~gmh/book.html) | |
--- | |
## Videos | |
[Adventure with Types in Haskell - Simon Peyton Jones](https://www.youtube.com/watch?v=6COvD8oynmI) | |
[What can Python learn from Haskell? - Bob Ippolito](https://www.youtube.com/watch?v=eVChXmNjV7o) | |
--- | |
## Exercises | |
[Exercism](http://exercism.io/) | |
--- | |
## Thanks! | |
Questions? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment