X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResource%2FDispatcher.hs;h=ffaba2d1ec114e49a3a22eb900a1bc81d286055e;hp=13080ee1da3a0e9fe32bca44152e6375cb774a58;hb=1ead053df6a792edafa9d714c4c038a8a9c3ad16;hpb=6cc54ccef706a0eba367e63c8b4248df81010f2a diff --git a/Network/HTTP/Lucu/Resource/Dispatcher.hs b/Network/HTTP/Lucu/Resource/Dispatcher.hs index 13080ee..ffaba2d 100644 --- a/Network/HTTP/Lucu/Resource/Dispatcher.hs +++ b/Network/HTTP/Lucu/Resource/Dispatcher.hs @@ -22,20 +22,21 @@ class Dispatchable α where dispatch ∷ α → CI Text → [ByteString] - → IO (Maybe ([ByteString], ResourceDef)) + → IO (Maybe ([ByteString], Resource)) dispatcher ∷ α → Dispatcher {-# INLINE dispatcher #-} dispatcher = Dispatcher --- |FIXME: doc +-- |Container type for 'Dispatchable' type class. data Dispatcher = ∀α. Dispatchable α ⇒ Dispatcher α instance Dispatchable Dispatcher where dispatch (Dispatcher α) = dispatch α dispatcher = id --- |FIXME: doc +-- |@a `'mappend'` b@ first tries to find a resource with @a@, and if +-- it returns 'Nothing', tries @b@ next. instance Monoid Dispatcher where {-# INLINE mempty #-} mempty = dispatcher () @@ -48,30 +49,33 @@ instance Monoid Dispatcher where Just _ → return r Nothing → dispatch β host path +-- |An IO-based dispatcher returning resource paths as well as +-- 'Resource's. instance Dispatchable (CI Text → [ByteString] - → IO (Maybe ([ByteString], ResourceDef))) where + → IO (Maybe ([ByteString], Resource))) where dispatch = id -instance Dispatchable (CI Text → [ByteString] → IO (Maybe ResourceDef)) where +-- |An IO-based dispatcher. +instance Dispatchable (CI Text → [ByteString] → IO (Maybe Resource)) where dispatch = ((((<$>) ∘ (<$>)) ((,) []) ∘) ∘) -instance Dispatchable (CI Text → [ByteString] → Maybe ResourceDef) where +-- |A pure dispatcher. +instance Dispatchable (CI Text → [ByteString] → Maybe Resource) where dispatch = (((return ∘ ((,) [] <$>)) ∘) ∘) -instance Dispatchable ([ByteString] → IO (Maybe ResourceDef)) where +-- |An IO-based dispatcher ignoring host names. +instance Dispatchable ([ByteString] → IO (Maybe Resource)) where dispatch = const ∘ (((<$>) ∘ (<$>)) ((,) []) ∘) -instance Dispatchable ([ByteString] → Maybe ResourceDef) where +-- |A pure dispatcher ignoring host names. +instance Dispatchable ([ByteString] → Maybe Resource) where dispatch = const ∘ ((return ∘ ((,) [] <$>)) ∘) -instance Dispatchable (IO (Maybe ResourceDef)) where - dispatch = const ∘ const ∘ ((<$>) ∘ (<$>)) ((,) []) - --- |The constant dispatcher returning always the same 'ResourceDef'. -instance Dispatchable ResourceDef where +-- |The constant dispatcher returning always the same 'Resource'. +instance Dispatchable Resource where dispatch = const ∘ const ∘ return ∘ Just ∘ (,) [] -- |The empty dispatcher returning always 'Nothing'. instance Dispatchable () where - dispatch _ _ _ = return Nothing \ No newline at end of file + dispatch _ _ _ = return Nothing