... | @@ -40,8 +40,8 @@ In response, programmers sometimes eschew type abstraction in favor of revealing |
... | @@ -40,8 +40,8 @@ In response, programmers sometimes eschew type abstraction in favor of revealing |
|
View patterns permit calling the view function inside the pattern and matching against the result:
|
|
View patterns permit calling the view function inside the pattern and matching against the result:
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
size (x | Unit <- x) = 1
|
|
size (x | Unit <- view x) = 1
|
|
size (x | Arrow t1 t2 <- x) = size t1 + size t2
|
|
size (x | Arrow t1 t2 <- view x) = size t1 + size t2
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
... | @@ -154,7 +154,7 @@ An example of using it: |
... | @@ -154,7 +154,7 @@ An example of using it: |
|
```wiki
|
|
```wiki
|
|
length :: JList a -> Integer
|
|
length :: JList a -> Integer
|
|
length (l | Nil <- view l) = 0
|
|
length (l | Nil <- view l) = 0
|
|
length (l | Cons x xs <- l) = 1 + length xs
|
|
length (l | Cons x xs <- view l) = 1 + length xs
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
... | | ... | |