root / Ganeti / HTools / Types.hs @ 9188aeef
History | View | Annotate | Download (946 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 name-to-idx mappings. |
15 |
type NameAssoc = [(String, Int)] |
16 |
|
17 |
{-| |
18 |
|
19 |
This is similar to the JSON library Result type - *very* similar, but |
20 |
we want to use it in multiple places, so we abstract it into a |
21 |
mini-library here |
22 |
|
23 |
-} |
24 |
data Result a |
25 |
= Bad String |
26 |
| Ok a |
27 |
deriving (Show) |
28 |
|
29 |
instance Monad Result where |
30 |
(>>=) (Bad x) _ = Bad x |
31 |
(>>=) (Ok x) fn = fn x |
32 |
return = Ok |
33 |
fail = Bad |
34 |
|
35 |
-- | A generic class for items that have updateable names and indices. |
36 |
class Element a where |
37 |
-- | Returns the name of the element |
38 |
nameOf :: a -> String |
39 |
-- | Returns the index of the element |
40 |
idxOf :: a -> Int |
41 |
-- | Updates the name of the element |
42 |
setName :: a -> String -> a |
43 |
-- | Updates the index of the element |
44 |
setIdx :: a -> Int -> a |