X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FStatusCode%2FInternal.hs;h=026b1a88b16bfdcb7094b8ae2d0dfe66f6f6508d;hb=eb77281;hp=38188568de8646037ee84465cce740e2df68b8d3;hpb=1376e182d0f455392dc15c4d93049d9031b36d00;p=Lucu.git diff --git a/Network/HTTP/Lucu/StatusCode/Internal.hs b/Network/HTTP/Lucu/StatusCode/Internal.hs index 3818856..026b1a8 100644 --- a/Network/HTTP/Lucu/StatusCode/Internal.hs +++ b/Network/HTTP/Lucu/StatusCode/Internal.hs @@ -4,6 +4,8 @@ , MultiParamTypeClasses , OverlappingInstances , TemplateHaskell + , TypeFamilies + , UndecidableInstances , UnicodeSyntax , ViewPatterns #-} @@ -11,8 +13,6 @@ module Network.HTTP.Lucu.StatusCode.Internal ( StatusCode(..) , SomeStatusCode - , (≈) - , (≉) , statusCodes ) where @@ -48,36 +48,9 @@ class (Eq sc, Show sc) ⇒ StatusCode sc where fromStatusCode ∷ sc → SomeStatusCode fromStatusCode = SomeStatusCode --- |Container type for the 'StatusCode' type class. -data SomeStatusCode - = ∀sc. StatusCode sc ⇒ SomeStatusCode sc - -instance Eq SomeStatusCode where - (==) = (≈) - -instance Show SomeStatusCode where - show (SomeStatusCode sc) = show sc - -infix 4 ≈, ≉ --- |Equivalence of 'StatusCode's. Two 'StatusCode's @a@ and @b@ are --- said to be equivalent iff @'numericCode' a '==' 'numericCode' b@. --- --- U+2248, ALMOST EQUAL TO -(≈) ∷ (StatusCode α, StatusCode β) ⇒ α → β → Bool -{-# INLINE (≈) #-} -α ≈ β = numericCode α ≡ numericCode β - --- |@(a ≉ b) '==' 'not' (a ≈ b)@ --- --- U+2249, NOT ALMOST EQUAL TO -(≉) ∷ (StatusCode α, StatusCode β) ⇒ α → β → Bool -{-# INLINE (≉) #-} -(≉) = ((¬) ∘) ∘ (≈) - -instance StatusCode SomeStatusCode where - numericCode (SomeStatusCode sc) = numericCode sc - textualStatus (SomeStatusCode sc) = textualStatus sc - fromStatusCode = id +instance StatusCode sc ⇒ ConvertSuccess sc SomeStatusCode where + {-# INLINE convertSuccess #-} + convertSuccess = fromStatusCode instance StatusCode sc ⇒ ConvertSuccess sc Ascii where {-# INLINE convertSuccess #-} @@ -87,6 +60,10 @@ instance StatusCode sc ⇒ ConvertSuccess sc AsciiBuilder where {-# INLINE convertSuccess #-} convertSuccess = textualStatus +instance StatusCode sc ⇒ ConvertAttempt sc SomeStatusCode where + {-# INLINE convertAttempt #-} + convertAttempt = return ∘ cs + instance StatusCode sc ⇒ ConvertAttempt sc Ascii where {-# INLINE convertAttempt #-} convertAttempt = return ∘ cs @@ -95,6 +72,25 @@ instance StatusCode sc ⇒ ConvertAttempt sc AsciiBuilder where {-# INLINE convertAttempt #-} convertAttempt = return ∘ cs +-- |Container type for the 'StatusCode' type class. +data SomeStatusCode + = ∀sc. StatusCode sc ⇒ SomeStatusCode sc + +-- |Equivalence of 'StatusCode's. Two 'StatusCode's @α@ and +-- @β@ are said to be equivalent iff @'numericCode' α '==' +-- 'numericCode' β@. +instance Eq SomeStatusCode where + {-# INLINE (==) #-} + (==) = (∘ numericCode) ∘ (==) ∘ numericCode + +instance Show SomeStatusCode where + show (SomeStatusCode sc) = show sc + +instance StatusCode SomeStatusCode where + numericCode (SomeStatusCode sc) = numericCode sc + textualStatus (SomeStatusCode sc) = textualStatus sc + fromStatusCode = id + -- |'QuasiQuoter' for 'StatusCode' declarations. -- -- Top-level splicing