Skip to content

Commit

Permalink
Tweak type-classes slides
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmcmiddlin committed May 14, 2019
1 parent 2a159d9 commit 42868af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions notes.org
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@

*** [[https://gitlab.haskell.org/ghc/ghc/wikis/roles2#join][roles2 on GHC wiki]]
*** [[http://web.cecs.pdx.edu/~mpj/pubs/fundeps-esop2000.pdf][type classes with functional dependencies paper]]
*** [[https://www.microsoft.com/en-us/research/wp-content/uploads/1997/01/multi.pdf][type classes design space paper]]
28 changes: 16 additions & 12 deletions slides/type-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,17 @@ Relaxes the rules for valid type class instances.

##

- Instance types can be type variables.
- Type variables can appear multiple times in the instance head.
- Concrete types may be used as parameters to instance types.

##

<pre class="haskell"><code data-trim data-noescape>
class Monad m => MonadReader r m where
ask :: m r
<span class="fragment fade-semi-out" data-fragment-index="1">class Monad m => MonadReader r m where
ask :: m r</span>

<span class="fragment">instance MonadReader r ((->) r) where
<span class="fragment" data-fragment-index="1">instance MonadReader r ((->) r) where
ask = id
</code></pre>

Expand Down Expand Up @@ -225,18 +231,18 @@ instance Twizzle (Maybe Integer) where
##

<pre class="no-highlight"><code data-trim data-noescape>
<span class="fragment fade-in-then-semi-out" data-fragment-index="1">$ ghc --version
<span class="fragment fade-semi-out" data-fragment-index="1">$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.4.4</span>

<span class="fragment fade-in-then-semi-out" data-fragment-index="2">$ ghc -Wall -fforce-recomp Main.hs -o whoopsie</span>
<span class="fragment fade-in-then-semi-out" data-fragment-index="3">[1 of 4] Compiling FIA ( FIA.hs, FIA.o )
<span class="fragment fade-in-then-semi-out" data-fragment-index="1">$ ghc -Wall -fforce-recomp Main.hs -o whoopsie</span>
<span class="fragment fade-in-then-semi-out" data-fragment-index="2">[1 of 4] Compiling FIA ( FIA.hs, FIA.o )
[2 of 4] Compiling FIB ( FIB.hs, FIB.o )
[3 of 4] Compiling FIC ( FIC.hs, FIC.o )
[4 of 4] Compiling Main ( Main.hs, Main.o )
Linking whoopsie ...</span>

<span class="fragment fade-in-then-semi-out" data-fragment-index="4">> ./whoopsie
fromList [</span><span class="fragment" data-fragment-index="4">Whoopsie A1 B C</span><span class="fragment fade-in-then-semi-out" data-fragment-index="4">,Whoopsie A2 B C,</span><span class="fragment" data-fragment-index="4">Whoopsie A1 B C</span><span class="fragment fade-in-then-semi-out" data-fragment-index="4">]</span><span class="fragment" data-fragment-index="5"></span>
<span class="fragment fade-in-then-semi-out" data-fragment-index="3">> ./whoopsie
fromList [</span><span class="fragment" data-fragment-index="3">Whoopsie A1 B C</span><span class="fragment fade-in-then-semi-out" data-fragment-index="3">,Whoopsie A2 B C,</span><span class="fragment" data-fragment-index="3">Whoopsie A1 B C</span><span class="fragment fade-in-then-semi-out" data-fragment-index="3">]</span><span class="fragment" data-fragment-index="5"></span>
</code></pre>

## `FlexibleContexts`
Expand Down Expand Up @@ -295,7 +301,7 @@ class Monad m => MonadReader r m where
<span class="fragment" data-fragment-index="2">foo ::
Integer
foo =
(+ 1) <$> ask $ 100</span>
(+ 1) <$> ask $ 41</span>
</code></pre>

::: {.notes}
Expand All @@ -319,7 +325,7 @@ foo =
In the expression: (+ 1) <$> ask
In the expression: (+ 1) <$> ask $ 100</span>
|
275 | (+ 1) <$> ask $ 100
275 | (+ 1) <$> ask $ 41
| ^^^
</code></pre>

Expand Down Expand Up @@ -390,8 +396,6 @@ foo =
{-# LANGUAGE MultiParamTypeClasses #-}
<mark>{-# LANGUAGE FunctionalDependencies #-}</mark>

module FunDeps where

<span class="fragment fade-in-then-semi-out" data-fragment-index="1">class Monad m => MonadReader r m</span> <span class="fragment" data-fragment-index="1">| m -> r </span><span class="fragment fade-in-then-semi-out" data-fragment-index="1">where
ask :: m r</span><span class="fragment" data-fragment-index="2"></span>

Expand Down

0 comments on commit 42868af

Please sign in to comment.