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