Statistics
| Branch: | Tag: | Revision:

root / Ganeti / HTools / Types.hs @ 262a08a2

History | View | Annotate | Download (760 Bytes)

1
{-| Some common types.
2

    
3
-}
4

    
5
module Ganeti.HTools.Types
6
    where
7

    
8
-- | The type used to hold idx-to-name mappings
9
type NameList = [(Int, String)]
10

    
11
-- | The type used to hold name-to-idx mappings
12
type NameAssoc = [(String, Int)]
13

    
14
{-|
15

    
16
This is similar to the JSON library Result type - *very* similar, but
17
we want to use it in multiple places, so we abstract it into a
18
mini-library here
19

    
20
-}
21
data Result a
22
    = Bad String
23
    | Ok a
24
    deriving (Show)
25

    
26
instance Monad Result where
27
    (>>=) (Bad x) _ = Bad x
28
    (>>=) (Ok x) fn = fn x
29
    return = Ok
30
    fail = Bad
31

    
32
-- | A generic class for items that have names and indices
33
class Element a where
34
    nameOf  :: a -> String
35
    idxOf   :: a -> Int
36
    setName :: a -> String -> a
37
    setIdx  :: a -> Int -> a