Created
November 2, 2017 23:15
-
-
Save ndtimofeev/fba406ec0dc5069b8ae60db0f5742ab6 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 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