Skip to content

Instantly share code, notes, and snippets.

@tel
Created January 1, 2015 16:32
Show Gist options
  • Save tel/dcff11ff677dd167b27a to your computer and use it in GitHub Desktop.
Save tel/dcff11ff677dd167b27a to your computer and use it in GitHub Desktop.
Really ugly Het Compose thing
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
module HetComp where
type family as ++ bs :: [k] where
'[] ++ bs = bs
(a ': as) ++ bs = a ': (as ++ bs)
data Comp :: [*] -> * -> * where
Inj :: (a -> b) -> Comp '[a] b
Id :: Comp '[a] a
Comp :: Comp as x -> Comp (x ': bs) r -> Comp (as ++ (x ': bs)) r
(>>>) :: Comp as x -> Comp (x ': bs) r -> Comp (as ++ (x ': bs)) r
(>>>) = Comp
infixr 9 >>>
ex1 :: Comp [Int, Int, Int, Int] Int
ex1 = Inj (+1) >>> Inj (+1) >>> Id >>> Inj (+1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment