On Fri, Dec 13, 2013 at 12:47:49PM +0100, Petr Pudlak wrote:
> This puts all PyValue code into one module, getting rid of orphan
> instances.
>
> Signed-off-by: Petr Pudlak <[email protected]>
> ---
> src/Ganeti/PyValueInstances.hs | 19 +++++++++++++++++--
> src/Ganeti/THH.hs | 17 ++---------------
> 2 files changed, 19 insertions(+), 17 deletions(-)
>
> diff --git a/src/Ganeti/PyValueInstances.hs b/src/Ganeti/PyValueInstances.hs
> index b1ca816..4464582 100644
> --- a/src/Ganeti/PyValueInstances.hs
> +++ b/src/Ganeti/PyValueInstances.hs
> @@ -27,9 +27,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> MA
> 02110-1301, USA.
>
> -}
> +{-# LANGUAGE ExistentialQuantification #-}
> {-# LANGUAGE FlexibleInstances, OverlappingInstances,
> TypeSynonymInstances, IncoherentInstances #-}
Everything in the same LANGUAGE pragma.
> -{-# OPTIONS_GHC -fno-warn-orphans #-}
Nice that this gets removed. Never liked this sort of stuff.
> module Ganeti.PyValueInstances where
>
> import Data.List (intercalate)
> @@ -38,7 +38,15 @@ import qualified Data.Map as Map
> import qualified Data.Set as Set (toList)
>
> import Ganeti.BasicTypes
> -import Ganeti.THH
> +
> +-- | Converts Haskell values into Python values
> +--
> +-- This is necessary for the default values of opcode parameters and
> +-- return values. For example, if a default value or return type is a
> +-- Data.Map, then it must be shown as a Python dictioanry.
> +class PyValue a where
> + showValue :: a -> String
> +
>
1 empty line instead of 2.
> instance PyValue Bool where
> showValue = show
> @@ -79,3 +87,10 @@ instance (PyValue k, PyValue a) => PyValue (Map k a) where
>
> instance PyValue a => PyValue (ListSet a) where
> showValue = showValue . Set.toList . unListSet
1 empty line instead of 2.
Rest LGTM.
Thanks,
Jose
> +
> +
> +-- | Encapsulates Python default values
> +data PyValueEx = forall a. PyValue a => PyValueEx a
> +
> +instance PyValue PyValueEx where
> + showValue (PyValueEx x) = showValue x
> diff --git a/src/Ganeti/THH.hs b/src/Ganeti/THH.hs
> index 363c230..8f4f73d 100644
> --- a/src/Ganeti/THH.hs
> +++ b/src/Ganeti/THH.hs
> @@ -1,4 +1,4 @@
> -{-# LANGUAGE ExistentialQuantification, ParallelListComp, TemplateHaskell #-}
> +{-# LANGUAGE ParallelListComp, TemplateHaskell #-}
>
> {-| TemplateHaskell helper for Ganeti Haskell code.
>
> @@ -77,6 +77,7 @@ import qualified Text.JSON as JSON
> import Text.JSON.Pretty (pp_value)
>
> import Ganeti.JSON
> +import Ganeti.PyValueInstances
>
> import Data.Maybe
> import Data.Functor ((<$>))
> @@ -584,20 +585,6 @@ type OpParam = (String, Q Type, Q Exp)
>
> -- * Python code generation
>
> --- | Converts Haskell values into Python values
> ---
> --- This is necessary for the default values of opcode parameters and
> --- return values. For example, if a default value or return type is a
> --- Data.Map, then it must be shown as a Python dictioanry.
> -class PyValue a where
> - showValue :: a -> String
> -
> --- | Encapsulates Python default values
> -data PyValueEx = forall a. PyValue a => PyValueEx a
> -
> -instance PyValue PyValueEx where
> - showValue (PyValueEx x) = showValue x
> -
> -- | Transfers opcode data between the opcode description (through
> -- @genOpCode@) and the Python code generation functions.
> type OpCodeDescriptor =
> --
> 1.8.5.1
>
--
Jose Antonio Lopes
Ganeti Engineering
Google Germany GmbH
Dienerstr. 12, 80331, München
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores
Steuernummer: 48/725/00206
Umsatzsteueridentifikationsnummer: DE813741370