Skip to content

Instantly share code, notes, and snippets.

@ndtimofeev
Created November 2, 2017 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndtimofeev/fba406ec0dc5069b8ae60db0f5742ab6 to your computer and use it in GitHub Desktop.
Save ndtimofeev/fba406ec0dc5069b8ae60db0f5742ab6 to your computer and use it in GitHub Desktop.
{-# LANGUAGE ExistentialQuantification #-}
import Data.Typeable
newtype Name = Name { getName :: Name }
newtype Phone = Phone { getPhone :: Int }
data Selection = Selection Int Int
data ExistPhone = forall t. (IsContact t, Typeable t) => MkPhone t
data PhoneContact = PhoneContact Name Phone
data PhoneWithSelectionContact = PhoneWithSelectionContact Name Phone Selection
class IsContact a
instance IsContact PhoneContact
instance IsContact PhoneWithSelectionContact
filterSelections :: [ExistPhone] -> [PhoneWithSelectionContact]
filterSelections = concatMap isSelection
where
isSelection :: ExistPhone -> [PhoneWithSelectionContact]
isSelection (MkPhone v)
| Just x <- cast v = [x]
| otherwise = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment