Skip to content

Instantly share code, notes, and snippets.

@Lysxia
Created February 27, 2020 15:28
Show Gist options
  • Save Lysxia/3461f489cc5057ea089e23a4eede375a to your computer and use it in GitHub Desktop.
Save Lysxia/3461f489cc5057ea089e23a4eede375a to your computer and use it in GitHub Desktop.
Left-to-right chain application
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, RebindableSyntax, TypeFamilies #-}
import Prelude (Int, IO, print, take, fromInteger, return)
import qualified Prelude
import Data.Function
x :: [Int]
x = [1,2,3] & take 2 & take 1
y :: [Int]
y = [1,2,3] & do
take 2
take 1
where
(>>) = flip (.)
z :: [Int]
z = (->>) [1,2,3]
(take 2)
(take 1)
class App a b where
(->>) :: a -> b
instance (a ~ a', App b c) => App a ((a' -> b) -> c) where
(->>) x y = (->>) (y x)
instance {-# OVERLAPPABLE #-} (a ~ a') => App a a' where
(->>) = id
main :: IO ()
main = do
print x
print y
print z
where
(>>) = (Prelude.>>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment