Last active
March 20, 2021 04:06
-
-
Save damhiya/d2439837a51c5d9a382709e9e7336008 to your computer and use it in GitHub Desktop.
NAry.hs
This file contains 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
fmap2 :: (Functor f1, Functor f2) => (a -> b) -> f1 (f2 a) -> f1 (f2 b) | |
fmap2 = fmap . fmap | |
for :: Functor f => f a -> (a -> b) -> f b | |
for = flip fmap | |
infixr $: | |
($:) :: (Functor f, Functor g) => f (g a) -> (a -> b) -> f (g b) | |
($:) = flip fmap2 | |
infixr $* | |
($*) :: Functor f => f a -> (b -> c) -> (a -> b) -> f c | |
f $* g = for f $: g | |
infixr $$ | |
($$) :: (Functor f, Functor g) => f a -> g b -> (a -> b -> c) -> f (g c) | |
f $$ g = for f $: for g | |
x = ((+1) $* (*4) $* id $* (+10) $$ const 1) (,,,,) 0 3 'A' 7 2 | |
-- x = (1,12,'A',17,1) | |
y = ((+1) $* (+2) $* (+3) $* (\(x,y,z) -> x+y+z)) (,,) 0 0 0 | |
-- y = 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment