Last active
July 24, 2020 14:07
-
-
Save prednaz/7d7143a1de8bcb7b20a3900b72c4c903 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Tuple a b = Tuple a b | |
snd :: Tuple a b -> b | |
snd = \tuple -> case tuple of Tuple _a b -> b | |
data List a = Cons a (List a) | Nil | |
foldr :: (a -> b -> b) -> b -> List a -> b | |
foldr = | |
\f initial list -> | |
case list of | |
Nil -> initial | |
Cons head tail -> f head (foldr f initial tail) | |
main = snd (foldr step (Tuple True Nil) (Cons 0 (Cons 1 (Cons 2 (Cons 3 Nil))))) | |
step = | |
\p1 p2 -> | |
case Tuple p1 p2 of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
snd (foldr step (Tuple True Nil) (Cons 0 (Cons 1 (Cons 2 (Cons 3 Nil))))) | |
(\tuple -> | |
case tuple of | |
Tuple _a b -> b) | |
(foldr step (Tuple True Nil) (Cons 0 (Cons 1 (Cons 2 (Cons 3 Nil))))) | |
case foldr step (Tuple True Nil) (Cons 0 (Cons 1 (Cons 2 (Cons 3 Nil)))) of | |
Tuple _a b -> b | |
case (\f initial list -> | |
case list of | |
Nil -> initial | |
Cons head tail -> f head (foldr f initial tail)) | |
step | |
(Tuple True Nil) | |
(Cons 0 (Cons 1 (Cons 2 (Cons 3 Nil)))) of | |
Tuple _a b -> b | |
case (\initial list -> | |
case list of | |
Nil -> initial | |
Cons head tail -> step head (foldr step initial tail)) | |
(Tuple True Nil) | |
(Cons 0 (Cons 1 (Cons 2 (Cons 3 Nil)))) of | |
Tuple _a b -> b | |
case (\list -> | |
case list of | |
Nil -> Tuple True Nil | |
Cons head tail -> step head (foldr step (Tuple True Nil) tail)) | |
(Cons 0 (Cons 1 (Cons 2 (Cons 3 Nil)))) of | |
Tuple _a b -> b | |
case (case Cons 0 (Cons 1 (Cons 2 (Cons 3 Nil))) of | |
Nil -> Tuple True Nil | |
Cons head tail -> step head (foldr step (Tuple True Nil) tail)) of | |
Tuple _a b -> b | |
case step 0 (foldr step (Tuple True Nil) (Cons 1 (Cons 2 (Cons 3 Nil)))) of | |
Tuple _a b -> b | |
case (\p1 p2 -> | |
case Tuple p1 p2 of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) | |
0 | |
(foldr step (Tuple True Nil) (Cons 1 (Cons 2 (Cons 3 Nil)))) of | |
Tuple _a b -> b | |
case (\p2 -> | |
case Tuple 0 p2 of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) | |
(foldr step (Tuple True Nil) (Cons 1 (Cons 2 (Cons 3 Nil)))) of | |
Tuple _a b -> b | |
case (case Tuple 0 (foldr step (Tuple True Nil) (Cons 1 (Cons 2 (Cons 3 Nil)))) of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) of | |
Tuple _a b -> b | |
case (case Tuple 0 | |
((\f initial list -> | |
case list of | |
Nil -> initial | |
Cons head tail -> f head (foldr f initial tail)) | |
step | |
(Tuple True Nil) | |
(Cons 1 (Cons 2 (Cons 3 Nil)))) of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) of | |
Tuple _a b -> b | |
case (case Tuple 0 | |
((\initial list -> | |
case list of | |
Nil -> initial | |
Cons head tail -> step head (foldr step initial tail)) | |
(Tuple True Nil) | |
(Cons 1 (Cons 2 (Cons 3 Nil)))) of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) of | |
Tuple _a b -> b | |
case (case Tuple 0 | |
((\list -> | |
case list of | |
Nil -> Tuple True Nil | |
Cons head tail -> step head (foldr step (Tuple True Nil) tail)) | |
(Cons 1 (Cons 2 (Cons 3 Nil)))) of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) of | |
Tuple _a b -> b | |
case (case Tuple 0 | |
(case Cons 1 (Cons 2 (Cons 3 Nil)) of | |
Nil -> Tuple True Nil | |
Cons head tail -> step head (foldr step (Tuple True Nil) tail)) of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) of | |
Tuple _a b -> b | |
case (case Tuple 0 (step 1 (foldr step (Tuple True Nil) (Cons 2 (Cons 3 Nil)))) of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) of | |
Tuple _a b -> b | |
case (case Tuple 0 | |
((\p1 p2 -> | |
case Tuple p1 p2 of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) | |
1 | |
(foldr step (Tuple True Nil) (Cons 2 (Cons 3 Nil)))) of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) of | |
Tuple _a b -> b | |
case (case Tuple 0 | |
((\p2 -> | |
case Tuple 1 p2 of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) | |
(foldr step (Tuple True Nil) (Cons 2 (Cons 3 Nil)))) of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) of | |
Tuple _a b -> b | |
case (case Tuple 0 | |
(case Tuple 1 (foldr step (Tuple True Nil) (Cons 2 (Cons 3 Nil))) of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) of | |
Tuple _a b -> b | |
case (case Tuple 0 (Tuple False (Cons 0 Nil)) of | |
Tuple 1 _ -> Tuple False (Cons 0 Nil) | |
Tuple x (Tuple b ys) -> Tuple True (Cons x ys)) of | |
Tuple _a b -> b | |
case Tuple True (Cons 0 (Cons 0 Nil)) of | |
Tuple _a b -> b | |
Cons 0 (Cons 0 Nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment