Commit c4d68e39 authored by Jose A. Lopes's avatar Jose A. Lopes

Move some 'PyValue' instances to a separate file

Move some 'PyValue' instances to a separate file so they can be
available to other modules which need these instances but do not want
to depend on the constants module, which led to compilation
constraints.
Signed-off-by: default avatarJose A. Lopes <jabolopes@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent eb0413c6
......@@ -644,6 +644,7 @@ HS_LIB_SRCS = \
src/Ganeti/OpParams.hs \
src/Ganeti/Path.hs \
src/Ganeti/Parsers.hs \
src/Ganeti/PyValueInstances.hs \
src/Ganeti/Query/Cluster.hs \
src/Ganeti/Query/Common.hs \
src/Ganeti/Query/Export.hs \
......
......@@ -52,36 +52,15 @@ import Ganeti.THH
import qualified Ganeti.Hs2Py.OpDoc as OpDoc
import Ganeti.OpParams
import Ganeti.PyValueInstances ()
import Ganeti.Types
import Ganeti.Query.Language (queryTypeOpToRaw)
import Data.List (intercalate)
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Ganeti.Constants as C
instance PyValue Bool
instance PyValue Int
instance PyValue Double
instance PyValue Char
instance (PyValue a, PyValue b) => PyValue (a, b) where
showValue (x, y) = show (showValue x, showValue y)
instance PyValue a => PyValue [a] where
showValue xs = show (map showValue xs)
instance PyValue a => PyValue (Set a) where
showValue s = showValue (Set.toList s)
instance (PyValue k, PyValue a) => PyValue (Map k a) where
showValue mp =
"{" ++ intercalate ", " (map showPair (Map.assocs mp)) ++ "}"
where showPair (k, x) = show k ++ ":" ++ show x
instance PyValue DiskIndex where
showValue = showValue . unDiskIndex
......
{-| PyValueInstances contains instances for the 'PyValue' typeclass.
The typeclass 'PyValue' converts Haskell values to Python values.
This module contains instances of this typeclass for several generic
types. These instances are used in the Haskell to Python generation
of opcodes and constants, for example.
-}
{-
Copyright (C) 2013 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
-}
{-# LANGUAGE FlexibleInstances, OverlappingInstances,
TypeSynonymInstances, IncoherentInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Ganeti.PyValueInstances where
import Data.List (intercalate)
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Set (Set)
import qualified Data.Set as Set
import Ganeti.THH
instance PyValue Bool
instance PyValue Int
instance PyValue Double
instance PyValue Char
instance (PyValue a, PyValue b) => PyValue (a, b) where
showValue (x, y) = show (showValue x, showValue y)
instance PyValue String where
showValue = show
instance PyValue a => PyValue [a] where
showValue xs = show (map showValue xs)
instance (PyValue k, PyValue a) => PyValue (Map k a) where
showValue mp =
"{" ++ intercalate ", " (map showPair (Map.assocs mp)) ++ "}"
where showPair (k, x) = show k ++ ":" ++ show x
instance PyValue a => PyValue (Set a) where
showValue s = showValue (Set.toList s)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment