Type.hs 1015 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. {-# LANGUAGE DeriveDataTypeable #-}
  2. {-# LANGUAGE BangPatterns #-}
  3. module Data.Adnot.Type (Value(..), Array, Product) where
  4. import Control.DeepSeq (NFData(..))
  5. import Data.Data (Data)
  6. import Data.Typeable (Typeable)
  7. import Data.Map.Strict (Map)
  8. import qualified Data.Map as M
  9. import Data.Text (Text)
  10. import Data.Vector (Vector)
  11. import GHC.Exts (IsString(..))
  12. -- | An Adnot value represented as a Haskell value
  13. data Value
  14. = Sum !Text !Array
  15. | Product !Product
  16. | List !Array
  17. | Integer !Integer
  18. | Double !Double
  19. | Symbol !Text
  20. | String !Text
  21. deriving (Eq, Show, Read, Typeable, Data)
  22. instance NFData Value where
  23. rnf (Sum t as) = rnf t `seq` rnf as
  24. rnf (Product ls) = rnf ls
  25. rnf (List as) = rnf as
  26. rnf (Integer i) = rnf i
  27. rnf (Double d) = rnf d
  28. rnf (Symbol t) = rnf t
  29. rnf (String t) = rnf t
  30. instance IsString Value where
  31. fromString = String . fromString
  32. type Array = Vector Value
  33. type Product = Map Text Value