From 9bb7c0933dcb44bb9d1eeff16b9646149a1db63d Mon Sep 17 00:00:00 2001 From: Philipp Balzarek Date: Thu, 14 Nov 2013 16:18:06 +0100 Subject: [PATCH] add Show instance to Annotation and add getAnnotation --- source/Network/Xmpp/Concurrent/Types.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/Network/Xmpp/Concurrent/Types.hs b/source/Network/Xmpp/Concurrent/Types.hs index a0f237d..f3f942e 100644 --- a/source/Network/Xmpp/Concurrent/Types.hs +++ b/source/Network/Xmpp/Concurrent/Types.hs @@ -26,10 +26,17 @@ type StanzaHandler = (Stanza -> IO Bool) -- ^ outgoing stanza -> IO [(Stanza, [Annotation])] -- ^ modified stanzas and -- /additional/ annotations -data Annotation = forall f. (Typeable f, Show f) => Annotation f +data Annotation = forall f.(Typeable f, Show f) => Annotation{fromAnnotation :: f} + +instance Show Annotation where + show (Annotation x) = "Annotation{ fromAnnotation = " ++ show x ++ "}" type Annotated a = (a, [Annotation]) +-- | Retrieve the first matching annotation +getAnnotation :: Typeable b => Annotated a -> Maybe b +getAnnotation = foldr (\(Annotation a) b -> maybe b Just $ cast a) Nothing . snd + data Plugin' = Plugin' { inHandler :: Stanza -> [Annotation] -> IO [(Stanza, [Annotation])]