root / Ganeti / HTools / Types.hs @ 19f38ee8
History | View | Annotate | Download (1019 Bytes)
1 |
{-| Some common types. |
---|---|
2 |
|
3 |
-} |
4 |
|
5 |
module Ganeti.HTools.Types |
6 |
( Idx |
7 |
, Ndx |
8 |
, NameAssoc |
9 |
, Result(..) |
10 |
, Element(..) |
11 |
) where |
12 |
|
13 |
-- | The instance index type. |
14 |
type Idx = Int |
15 |
|
16 |
-- | The node index type. |
17 |
type Ndx = Int |
18 |
|
19 |
-- | The type used to hold name-to-idx mappings. |
20 |
type NameAssoc = [(String, Int)] |
21 |
|
22 |
{-| |
23 |
|
24 |
This is similar to the JSON library Result type - *very* similar, but |
25 |
we want to use it in multiple places, so we abstract it into a |
26 |
mini-library here |
27 |
|
28 |
-} |
29 |
data Result a |
30 |
= Bad String |
31 |
| Ok a |
32 |
deriving (Show) |
33 |
|
34 |
instance Monad Result where |
35 |
(>>=) (Bad x) _ = Bad x |
36 |
(>>=) (Ok x) fn = fn x |
37 |
return = Ok |
38 |
fail = Bad |
39 |
|
40 |
-- | A generic class for items that have updateable names and indices. |
41 |
class Element a where |
42 |
-- | Returns the name of the element |
43 |
nameOf :: a -> String |
44 |
-- | Returns the index of the element |
45 |
idxOf :: a -> Int |
46 |
-- | Updates the name of the element |
47 |
setName :: a -> String -> a |
48 |
-- | Updates the index of the element |
49 |
setIdx :: a -> Int -> a |