Revision 2886c58d
b/src/Ganeti/PyValueInstances.hs | ||
---|---|---|
27 | 27 |
02110-1301, USA. |
28 | 28 |
|
29 | 29 |
-} |
30 |
{-# LANGUAGE ExistentialQuantification #-} |
|
30 | 31 |
{-# LANGUAGE FlexibleInstances, OverlappingInstances, |
31 | 32 |
TypeSynonymInstances, IncoherentInstances #-} |
32 |
{-# OPTIONS_GHC -fno-warn-orphans #-} |
|
33 | 33 |
module Ganeti.PyValueInstances where |
34 | 34 |
|
35 | 35 |
import Data.List (intercalate) |
... | ... | |
38 | 38 |
import qualified Data.Set as Set (toList) |
39 | 39 |
|
40 | 40 |
import Ganeti.BasicTypes |
41 |
import Ganeti.THH |
|
41 |
|
|
42 |
-- * PyValue represents data types convertible to Python |
|
43 |
|
|
44 |
-- | Converts Haskell values into Python values |
|
45 |
-- |
|
46 |
-- This is necessary for the default values of opcode parameters and |
|
47 |
-- return values. For example, if a default value or return type is a |
|
48 |
-- Data.Map, then it must be shown as a Python dictioanry. |
|
49 |
class PyValue a where |
|
50 |
showValue :: a -> String |
|
42 | 51 |
|
43 | 52 |
instance PyValue Bool where |
44 | 53 |
showValue = show |
... | ... | |
79 | 88 |
|
80 | 89 |
instance PyValue a => PyValue (ListSet a) where |
81 | 90 |
showValue = showValue . Set.toList . unListSet |
91 |
|
|
92 |
-- * PyValue represents an unspecified value convertible to Python |
|
93 |
|
|
94 |
-- | Encapsulates Python default values |
|
95 |
data PyValueEx = forall a. PyValue a => PyValueEx a |
|
96 |
|
|
97 |
instance PyValue PyValueEx where |
|
98 |
showValue (PyValueEx x) = showValue x |
b/src/Ganeti/THH.hs | ||
---|---|---|
1 |
{-# LANGUAGE ExistentialQuantification, ParallelListComp, TemplateHaskell #-}
|
|
1 |
{-# LANGUAGE ParallelListComp, TemplateHaskell #-} |
|
2 | 2 |
|
3 | 3 |
{-| TemplateHaskell helper for Ganeti Haskell code. |
4 | 4 |
|
... | ... | |
77 | 77 |
import Text.JSON.Pretty (pp_value) |
78 | 78 |
|
79 | 79 |
import Ganeti.JSON |
80 |
import Ganeti.PyValueInstances |
|
80 | 81 |
|
81 | 82 |
import Data.Maybe |
82 | 83 |
import Data.Functor ((<$>)) |
... | ... | |
584 | 585 |
|
585 | 586 |
-- * Python code generation |
586 | 587 |
|
587 |
-- | Converts Haskell values into Python values |
|
588 |
-- |
|
589 |
-- This is necessary for the default values of opcode parameters and |
|
590 |
-- return values. For example, if a default value or return type is a |
|
591 |
-- Data.Map, then it must be shown as a Python dictioanry. |
|
592 |
class PyValue a where |
|
593 |
showValue :: a -> String |
|
594 |
|
|
595 |
-- | Encapsulates Python default values |
|
596 |
data PyValueEx = forall a. PyValue a => PyValueEx a |
|
597 |
|
|
598 |
instance PyValue PyValueEx where |
|
599 |
showValue (PyValueEx x) = showValue x |
|
600 |
|
|
601 | 588 |
-- | Transfers opcode data between the opcode description (through |
602 | 589 |
-- @genOpCode@) and the Python code generation functions. |
603 | 590 |
type OpCodeDescriptor = |
Also available in: Unified diff