-
-
Save nomeata/b9d3e18a49f0c320c0d1f0e7b72a9c73 to your computer and use it in GitHub Desktop.
Code for https://youtu.be/upLrw7N3xpI
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
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeOperators #-} | |
module Z where | |
import Prelude hiding (zip) | |
zip :: forall a b. [a] -> [b] -> [(a,b)] | |
zip [] _ = [] | |
zip _ [] = [] | |
zip (x:xs) (y:ys) = (x,y) : zip xs ys | |
zip2 :: forall a b. [a] -> [b] -> [(a,b)] | |
zip2 xs ys = (foo xs) (bar ys) | |
where | |
foo :: [a] -> Z a b -> [(a,b)] | |
foo [] = \_ -> [] | |
foo (x:xs) = \r -> runZ r (foo xs) x | |
bar :: [b] -> Z a b | |
bar [] = Z $ \xys x -> [] | |
bar (y:ys) = Z $ \xys x -> (x,y) : xys (bar ys) | |
newtype Z a b = Z { runZ :: (Z a b -> [(a, b)]) -> a -> [(a, b)] } | |
newtype a -&> b = Hyp { invoke :: (b -&> a) -> b } | |
-- a -&> b == (b -&> a) -> b | |
-- == ((a -&> b) -> a) -> b | |
-- | |
-- Z a b == (Z a b -> [(a, b)]) -> (a -> [(a, b)]) | |
-- | |
-- Z a b = [(a, b)] -&> (a -> [(a,b)]) | |
zip3 :: forall a b. [a] -> [b] -> [(a,b)] | |
zip3 xs ys = invoke (foo xs) (bar ys) | |
where | |
foo :: [a] -> (a -> [(a,b)]) -&> [(a,b)] | |
foo [] = Hyp $ \_ -> [] | |
foo (x:xs) = Hyp $ \r -> invoke r (foo xs) x | |
bar :: [b] -> [(a, b)] -&> (a -> [(a,b)]) | |
bar [] = Hyp $ \xys x -> [] | |
bar (y:ys) = Hyp $ \xys x -> (x,y) : invoke xys (bar ys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment