Skip to content

Instantly share code, notes, and snippets.

@googleson78
Created November 23, 2020 08:27
Show Gist options
  • Save googleson78/df9f4a92df974d17c0ff8c91f2b8dcc9 to your computer and use it in GitHub Desktop.
Save googleson78/df9f4a92df974d17c0ff8c91f2b8dcc9 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE InstanceSigs #-}
class ApplyCompose b c x res | b c x -> res where
(<|) :: (b -> c) -> x -> res
instance ApplyCompose b c (a -> b) (a -> c) where
(<|) :: (b -> c) -> (a -> b) -> a -> c
(<|) = (.)
instance ApplyCompose b c b c where
(<|) :: (b -> c) -> b -> c
(<|) = ($)
infixr 1 <|
-- > isSpace <| 'a'
-- False
-- > isSpace <| toEnum @Char <| (97 :: Int)
-- False
-- > (isSpace <| toEnum <| (97 :: Int)) :: Bool
-- ambiguity error
-- > f = map <| map id
-- ambiguity error
-- > f = (map <| map id) :: [[Int]] -> [[Int]]
-- ambiguity error
-- > f = map @[Int] @[Int] <| map @Int id
-- > :t f
-- f :: [[Int]] -> [[Int]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment