mirror of
https://github.com/sdiehl/write-you-a-haskell.git
synced 2024-09-11 11:46:57 +03:00
case expansion algorithm
This commit is contained in:
parent
7662432760
commit
0b2fa923d7
@ -94,8 +94,12 @@ Notation Haskell Type
|
||||
``Empty`` ``Void``
|
||||
``Unit`` ``()``
|
||||
|
||||
Recursive Types
|
||||
---------------
|
||||
Isorecursive Types
|
||||
-------------------
|
||||
|
||||
$$
|
||||
\mathtt{Nat} = \mu \alpha. 1 + \alpha
|
||||
$$
|
||||
|
||||
```haskell
|
||||
roll :: Rec f -> f (Rec f)
|
||||
@ -105,10 +109,6 @@ unroll :: f (Rec f) -> Rec f
|
||||
unroll f = Rec f
|
||||
```
|
||||
|
||||
$$
|
||||
\mathtt{Nat} = \mu \alpha. 1 + \alpha
|
||||
$$
|
||||
|
||||
Peano numbers:
|
||||
|
||||
```haskell
|
||||
@ -343,6 +343,31 @@ main = do
|
||||
|
||||
* [Generics](https://github.com/sdiehl/write-you-a-haskell/tree/master/chapter10/generics.hs)
|
||||
|
||||
Wadler's Algorithm
|
||||
------------------
|
||||
|
||||
Consider the task of expanding
|
||||
|
||||
```haskell
|
||||
f :: Just (Either a b) -> Int
|
||||
f (Just (Left x)) = 1
|
||||
f (Just (Right x)) = 2
|
||||
f Nothing = 3
|
||||
```
|
||||
|
||||
|
||||
```haskell
|
||||
f :: Maybe (Either a b) -> Int
|
||||
f = case ds of _ {
|
||||
Nothing -> I# 3;
|
||||
Just ds1 ->
|
||||
case ds1 of _ {
|
||||
Left x -> I# 1;
|
||||
Right x -> I# 2
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Full Source
|
||||
-----------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user