constraints 0.3.5 → 0.4
raw patch · 2 files changed
+42/−6 lines, 2 files
Files
- Data/Constraint.hs +40/−4
- constraints.cabal +2/−2
Data/Constraint.hs view
@@ -15,6 +15,7 @@ {-# LANGUAGE CPP #-} #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707 {-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE RoleAnnotations #-} #endif -----------------------------------------------------------------------------@@ -55,14 +56,32 @@ import Data.Monoid import Data.Complex import Data.Ratio+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707+import Data.Data+#endif import GHC.Prim (Constraint) -- | Capture a dictionary for a given constraint data Dict :: Constraint -> * where Dict :: a => Dict a- #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707+ deriving Typeable+ type role Dict nominal++instance (Typeable p, p) => Data (Dict p) where+ gfoldl _ z Dict = z Dict+ toConstr _ = dictConstr+ gunfold _ z c = case constrIndex c of+ 1 -> z Dict+ _ -> error "gunfold"+ dataTypeOf _ = dictDataType++dictConstr :: Constr+dictConstr = mkConstr dictDataType "Dict" [] Prefix++dictDataType :: DataType+dictDataType = mkDataType "Data.Constraint.Dict" [dictConstr] #endif deriving instance Eq (Dict a)@@ -72,10 +91,28 @@ infixr 9 :- newtype a :- b = Sub (a => Dict b) #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707+ deriving Typeable+ type role (:-) nominal nominal-#endif -#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707+-- TODO: _proper_ Data for (p :- q) requires (:-) to be cartesian closed.+-- This is admissable, but not present by default++-- constraint should be instance (Typeable p, Typeable q, p |- q) => Data (p :- q)+instance (Typeable p, Typeable q, p, q) => Data (p :- q) where+ gfoldl _ z (Sub Dict) = z (Sub Dict)+ toConstr _ = subConstr+ gunfold _ z c = case constrIndex c of+ 1 -> z (Sub Dict)+ _ -> error "gunfold"+ dataTypeOf _ = subDataType++subConstr :: Constr+subConstr = mkConstr dictDataType "Sub" [] Prefix++subDataType :: DataType+subDataType = mkDataType "Data.Constraint.:-" [subConstr]+ instance Category (:-) where id = refl (.) = trans@@ -356,4 +393,3 @@ instance a => Monoid (Dict a) where mappend Dict Dict = Dict mempty = Dict-
constraints.cabal view
@@ -1,6 +1,6 @@ name: constraints category: Constraints-version: 0.3.5+version: 0.4 license: BSD3 cabal-version: >= 1.10 license-file: LICENSE@@ -22,7 +22,7 @@ library default-language: Haskell2010- other-extensions+ other-extensions: FunctionalDependencies, ScopedTypeVariables, StandaloneDeriving,