From: PHO Date: Fri, 23 Apr 2010 09:50:54 +0000 (+0900) Subject: revised HLength X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=hs-rrdtool.git;a=commitdiff_plain;h=57b97113a93d366f14278a12b8170a1c06e258a1 revised HLength --- diff --git a/Data/HList.hs b/Data/HList.hs index e1e7769..e39fb95 100644 --- a/Data/HList.hs +++ b/Data/HList.hs @@ -18,6 +18,8 @@ module Data.HList , HConcat , HMap + + , HLength ) where diff --git a/Data/HList/Prelude.hs b/Data/HList/Prelude.hs index 3ab596f..c63be3a 100644 --- a/Data/HList/Prelude.hs +++ b/Data/HList/Prelude.hs @@ -28,7 +28,7 @@ module Data.HList.Prelude , HConcatable(..) , HMappable(..) - , HLength(..) + , HLength ) where @@ -158,16 +158,6 @@ instance ( Applyable f x hMap f (HCons x xs) = hCons (apply f x) (hMap f xs) -- HLength -class IntegerT (HLengthOf l) => HLength l where - type HLengthOf l - hLength :: Integral n => l -> n - -instance HLength HNil where - type HLengthOf HNil = D0 - hLength _ = 0 - -instance ( HLength l - , IntegerT (Succ (HLengthOf l)) - ) => HLength (HCons e l) where - type HLengthOf (HCons e l) = Succ (HLengthOf l) - hLength (HCons _ l) = 1 + hLength l +type family HLength l +type instance HLength HNil = D0 +type instance HLength (HCons e l) = Succ (HLength l) diff --git a/Data/HList/String.hs b/Data/HList/String.hs index e3f878a..6d4d52d 100644 --- a/Data/HList/String.hs +++ b/Data/HList/String.hs @@ -11,11 +11,17 @@ import Types.Data.Num.Decimal.Literals.TH import Types.Data.Num.Ops -class HString s +class (Show s, Eq s) => HString s instance HString HNil -instance IntegerT c => HString (HCons c s) +instance ( Show c + , Show s + , Eq c + , Eq s + , IntegerT c + ) + => HString (HCons c s) hString :: QuasiQuoter hString = QuasiQuoter quoteStrExp quoteStrPat diff --git a/Database/RRDtool/Create.hs b/Database/RRDtool/Create.hs index cb41c21..a3b51e5 100644 --- a/Database/RRDtool/Create.hs +++ b/Database/RRDtool/Create.hs @@ -11,7 +11,7 @@ module Database.RRDtool.Create -- Database.RRDtool.Expression , Constant(..) - , IsVarName(..) + , IsVarName , Variable(..) , CommonUnaryOp(..) , CommonBinaryOp(..) diff --git a/Database/RRDtool/Expression.hs b/Database/RRDtool/Expression.hs index 669acbc..ec5b23a 100644 --- a/Database/RRDtool/Expression.hs +++ b/Database/RRDtool/Expression.hs @@ -11,7 +11,7 @@ module Database.RRDtool.Expression , IsCommonExprSet , Constant(..) - , IsVarName(..) + , IsVarName , Variable(..) , IsVariableSet , CommonUnaryOp(..) @@ -29,6 +29,7 @@ module Database.RRDtool.Expression where import Data.HList +import Data.HList.String -- MentionedVars @@ -66,8 +67,13 @@ instance IsCommonExpr Constant instance MentionedVars Constant where type MentionedVarsOf Constant = HNil -class (Show a, Eq a, Ord a) => IsVarName a where - varName :: a -> String +{- This is what we want to do but GHC can't handle this for now. +class ( (HLengthOf a :<=: D255) ~ True + , HString a + ) + => IsVarName a +-} +class HString a => IsVarName a data Variable vn = Variable !vn