Skip to content

Instantly share code, notes, and snippets.

@adetokunbo
Forked from rampion/HFilter.hs
Created August 28, 2021 04:21
Show Gist options
  • Save adetokunbo/f180202905a14a1f6e69c1cf46892cc4 to your computer and use it in GitHub Desktop.
Save adetokunbo/f180202905a14a1f6e69c1cf46892cc4 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