master
nihonium 2 years ago
parent f348445975
commit a7309c7473
No known key found for this signature in database
GPG Key ID: 0251623741027CFC

@ -0,0 +1,13 @@
newtype CustomList a = CustomList [a] deriving Show
instance Functor CustomList where
fmap f (CustomList lst) = CustomList $ fmap f lst
instance Applicative CustomList where
pure x = CustomList $ repeat x
{-
-- default implementation
pure x = CustomList [x]
(CustomList fs) <*> (CustomList xs) = CustomList $ [f x | f <- fs, x <- xs]
-}
(CustomList fs) <*> (CustomList xs) = CustomList $ zipWith ($) fs xs

@ -16,7 +16,7 @@ u <*> (v <*> w) == pure (.) <*> u <*> v <*> w
## Доказательство ## Доказательство
### Identity ### 1.Identity
``` ```
pure id <*> CustomList lst == pure id <*> CustomList lst ==
@ -45,10 +45,6 @@ pure ($ y) <*> u ==
CustomList $ repeat ($ y) <*> CustomList fs == CustomList $ repeat ($ y) <*> CustomList fs ==
CustomList $ zipWith ($) (repeat ($ y)) fs [2] 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 ($) f x == ($) ($ x) f
=> [1] == [2] => [1] == [2]
@ -62,10 +58,10 @@ CustomList fs2 <*> (CustomList fs1 <*> CustomList xs) ==
CustomList fs2 <*> CustomList $ zipWith ($) fs1 xs == CustomList fs2 <*> CustomList $ zipWith ($) fs1 xs ==
CustomList fs2 <*> CustomList xs1 == CustomList fs2 <*> CustomList xs1 ==
... == ... ==
CustomList xs12 (Длина xs12 - наименьшая из длин fs1, fs2 и xs) CustomList xs12 (Длина xs12 - наименьшая из длин fs1, fs2 и xs, сначала применены ф-ии из fs1, потом - из fs2)
pure (.) <*> u <*> v <*> w == pure (.) <*> u <*> v <*> w ==
pure (.) CustomList fs2 <*> CustomList fs1 <*> CustomList xs == pure (.) CustomList fs2 <*> CustomList fs1 <*> CustomList xs ==
CustomList fs12 <*> Custom xs == (fs12 - список из композиций соответствующих функций, длина fs12 - наименьшая из длин fs1 и fs2) CustomList fs12 <*> Custom xs == (fs12 - список из композиций соответствующих функций, длина fs12 - наименьшая из длин fs1 и fs2)
CustomList xs12 (длина xs12 - наименьшая из длин fs12 и xs) CustomList xs12 (длина xs12 - наименьшая из длин fs12 и xs, сначала применены ф-ии из fs1, потом - из fs2))
``` ```