You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.6 KiB
Markdown
72 lines
1.6 KiB
Markdown
2 years ago
|
### Законы
|
||
|
|
||
|
```
|
||
|
--Identity
|
||
|
pure id <*> x == x
|
||
|
|
||
|
--2.Homomorphism
|
||
|
pure f <*> pure x == pure (f x)
|
||
|
|
||
|
--3.Interchange
|
||
|
u <*> pure y == pure ($ y) <*> u
|
||
|
|
||
|
--4.Composition
|
||
|
u <*> (v <*> w) == pure (.) <*> u <*> v <*> w
|
||
|
```
|
||
|
|
||
|
## Доказательство
|
||
|
|
||
|
### Identity
|
||
|
|
||
|
```
|
||
|
pure id <*> CustomList lst ==
|
||
|
CustomList $ repeat id <*> CustomList lst ==
|
||
|
CustomList $ zipWith ($) (repeat id) lst ==
|
||
|
CustomList lst
|
||
|
```
|
||
|
|
||
|
### 2.Homomorphism
|
||
|
|
||
|
```
|
||
|
pure f <*> pure x ==
|
||
|
CustomList $ repeat f <*> CustomList $ repeat x ==
|
||
|
CustomList $ zipWith ($) (repeat f) (repeat x) ==
|
||
|
CustomList $ repeat (f x)
|
||
|
```
|
||
|
|
||
|
### 3.Interchange
|
||
|
|
||
|
```
|
||
|
u <*> pure y ==
|
||
|
CustomList fs <*> CustomList $ repeat y ==
|
||
|
CustomList $ zipWith ($) fs (repeat y) [1]
|
||
|
|
||
|
pure ($ y) <*> u ==
|
||
|
CustomList $ repeat ($ y) <*> CustomList fs ==
|
||
|
CustomList $ zipWith ($) (repeat ($ y)) fs [2]
|
||
|
|
||
|
Type of ($ y): (a -> b) -> b
|
||
|
Type of ($): (a -> b) -> a -> b
|
||
|
Type of ($) ($ y): (a -> b) -> b
|
||
|
|
||
|
($) f x == ($) ($ x) f
|
||
|
|
||
|
=> [1] == [2]
|
||
|
```
|
||
|
|
||
|
### 4.Composition
|
||
|
|
||
|
```
|
||
|
u <*> (v <*> w) ==
|
||
|
CustomList fs2 <*> (CustomList fs1 <*> CustomList xs) ==
|
||
|
CustomList fs2 <*> CustomList $ zipWith ($) fs1 xs ==
|
||
|
CustomList fs2 <*> CustomList xs1 ==
|
||
|
... ==
|
||
|
CustomList xs12 (Длина xs12 - наименьшая из длин fs1, fs2 и xs)
|
||
|
|
||
|
pure (.) <*> u <*> v <*> w ==
|
||
|
pure (.) CustomList fs2 <*> CustomList fs1 <*> CustomList xs ==
|
||
|
CustomList fs12 <*> Custom xs == (fs12 - список из композиций соответствующих функций, длина fs12 - наименьшая из длин fs1 и fs2)
|
||
|
CustomList xs12 (длина xs12 - наименьшая из длин fs12 и xs)
|
||
|
```
|