Commits

Iago Abal  committed 9755ba4

Add "Typeable BV" and "Data BV" instances

  • Participants
  • Parent commits ff2e022

Comments (0)

Files changed (1)

File Data/BitVector.hs

 import Data.Bits
 import Data.List ( foldl1' )
 import Data.Ord
+import Data.Typeable ( Typeable(..), mkTyConApp, mkTyCon3 )
+import Data.Data 
+  ( Data(..), Fixity(Prefix)
+  , constrIndex, indexConstr, mkDataType, mkConstr 
+  )
 
 ----------------------------------------------------------------------
 --- Bit-vectors
 
 instance Show BV where
   show (BV n a) = "[" ++ show n ++ "]" ++ show a
+ 
+instance Typeable BV where
+  typeOf _ = mkTyConApp bvTyCon []
+    where bvTyCon = mkTyCon3 "bv" "Data.BitVector" "BV"
+
+instance Data BV where
+  gfoldl k r (BV x1 x2) = r BV `k` x1 `k` x2
+  gunfold k z c
+    = case constrIndex c - 1 of
+          0 -> k $ k $ z BV
+          i -> error $ "Data.gunfold for BV, unknown index: " ++ show i
+  toConstr x@BV{} = indexConstr (dataTypeOf x) 1
+  dataTypeOf _ = ty
+    where ty = mkDataType "Data.BitVector.BV" 
+                  [mkConstr ty "BV" ["size", "nat"] Prefix]
 
 ----------------------------------------------------------------------
 --- Construction