Skip to content

Instantly share code, notes, and snippets.

@rampion
Created February 22, 2012 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rampion/1885439 to your computer and use it in GitHub Desktop.
Save rampion/1885439 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module HFilter where
data a :* b = a :* b
deriving (Show, Eq)
infixr 5 :*
hlist :: Int :* String :* Int :* Maybe Float :* ()
hlist = 1 :* "hello" :* 2 :* Just 3 :* ()
class TypeFilter h a h' where
hfilter :: a -> h -> h'
instance TypeFilter () a () where
hfilter _ = id
instance TypeFilter h a h' => TypeFilter (t :* h) a h' where
hfilter a' (_ :* h) = hfilter a' h
instance TypeFilter h a h' => TypeFilter (a :* h) a (a :* h') where
hfilter a' (a :* h) = a :* hfilter a' h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment