Statistics
| Branch: | Tag: | Revision:

root / Ganeti / HTools / Types.hs @ 608efcce

History | View | Annotate | Download (846 Bytes)

1
{-| Some common types.
2

    
3
-}
4

    
5
module Ganeti.HTools.Types
6
    where
7

    
8
-- | The instance index type
9
type Idx = Int
10

    
11
-- | The node index type
12
type Ndx = Int
13

    
14
-- | The type used to hold idx-to-name mappings
15
type NameList = [(Int, String)]
16

    
17
-- | The type used to hold name-to-idx mappings
18
type NameAssoc = [(String, Int)]
19

    
20
{-|
21

    
22
This is similar to the JSON library Result type - *very* similar, but
23
we want to use it in multiple places, so we abstract it into a
24
mini-library here
25

    
26
-}
27
data Result a
28
    = Bad String
29
    | Ok a
30
    deriving (Show)
31

    
32
instance Monad Result where
33
    (>>=) (Bad x) _ = Bad x
34
    (>>=) (Ok x) fn = fn x
35
    return = Ok
36
    fail = Bad
37

    
38
-- | A generic class for items that have names and indices
39
class Element a where
40
    nameOf  :: a -> String
41
    idxOf   :: a -> Int
42
    setName :: a -> String -> a
43
    setIdx  :: a -> Int -> a