Created
November 3, 2017 00:09
-
-
Save ndtimofeev/c46b28e9c9a4ee9d689cbc9d753a6d08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeOperators, TypeInType, GADTs, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts #-} | |
data HList (xs :: [k]) where | |
Z :: HList '[] | |
(:.) :: a -> HList xs -> HList (a ': xs) | |
infixr 5 :. | |
class Filter a xs where | |
typeFilter :: HList xs -> [a] | |
instance Filter a '[] where | |
typeFilter _ = [] | |
instance Filter a xs => Filter a (a ': xs) where | |
typeFilter (v :. xs) = v : typeFilter xs | |
instance Filter a xs => Filter a (b ': xs) where | |
typeFilter (v :. xs) = typeFilter xs | |
newtype Name = Name { getName :: Name } | |
newtype Phone = Phone { getPhone :: Int } | |
data Selection = Selection Int Int | |
data PhoneContact = PhoneContact Name Phone | |
data PhoneWithSelectionContact = PhoneWithSelectionContact Name Phone Selection | |
class IsContact a | |
instance IsContact PhoneContact | |
instance IsContact PhoneWithSelectionContact | |
filterSelections :: Filter PhoneWithSelectionContact xs => HList xs -> [PhoneWithSelectionContact] | |
filterSelections = typeFilter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment