diff options
Diffstat (limited to 'src/Types.hs')
-rw-r--r-- | src/Types.hs | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/src/Types.hs b/src/Types.hs index 2dff0f0..10cea7a 100644 --- a/src/Types.hs +++ b/src/Types.hs | |||
@@ -1,57 +1,57 @@ | |||
1 | {-# LANGUAGE TemplateHaskell, OverloadedStrings #-} | 1 | {-# LANGUAGE TemplateHaskell, OverloadedStrings, ConstraintKinds, FlexibleContexts #-} |
2 | {-# LANGUAGE FlexibleInstances, UndecidableInstances, MultiParamTypeClasses #-} | ||
2 | 3 | ||
3 | module Types | 4 | module Types |
4 | ( Entity(..) | 5 | ( Entity(..) |
5 | , showEntity | 6 | , SequenceValue |
6 | , Comment | 7 | , Comment |
7 | , Alteration(..) | 8 | , Alteration(..) |
8 | , SequenceState, queue, history | 9 | , Sequence |
10 | , History | ||
11 | , SequenceM | ||
9 | ) where | 12 | ) where |
10 | 13 | ||
11 | import Data.PQueue.Prio.Max (MaxPQueue) | 14 | import Data.PQueue.Prio.Max (MaxPQueue) |
12 | import qualified Data.PQueue.Prio.Max as MaxPQueue | 15 | import qualified Data.PQueue.Prio.Max as MaxPQueue (empty) |
13 | 16 | ||
14 | import Data.Sequence (Seq) | 17 | import Data.Sequence (Seq) |
15 | import qualified Data.Sequence as Seq | ||
16 | 18 | ||
17 | import Data.Monoid (Monoid(..), (<>)) | 19 | import Data.Text (Text) |
18 | 20 | ||
19 | import Control.Monad.State.Lazy (MonadState) | 21 | import Data.Default.Class |
20 | import Control.Monad.IO.Class (MonadIO) | ||
21 | 22 | ||
22 | import Data.Text (Text) | 23 | import Control.Monad.State.Strict (MonadState(..), MonadTrans(..)) |
23 | import qualified Data.Text as Text | 24 | import Control.Monad.Writer.Strict (MonadWriter, MonadTrans(..)) |
24 | import qualified Data.Text.IO as Text | ||
25 | 25 | ||
26 | import Control.Lens.TH | 26 | import Control.Monad.IO.Class (MonadIO) |
27 | 27 | ||
28 | import Data.Default.Class | 28 | import System.Console.Haskeline (InputT) |
29 | 29 | ||
30 | |||
30 | data Entity = Entity Text (Maybe Integer) | 31 | data Entity = Entity Text (Maybe Integer) |
31 | deriving (Eq, Ord, Show) | 32 | deriving (Eq, Ord, Show) |
32 | 33 | ||
33 | showEntity :: Entity -> Text | 34 | type SequenceValue = Integer |
34 | showEntity (Entity t Nothing) = t | ||
35 | showEntity (Entity t (Just n)) = t <> " " <> (Text.pack $ show n) | ||
36 | 35 | ||
37 | type Comment = Text | 36 | type Comment = Text |
38 | 37 | ||
39 | data Alteration = Modify Entity Integer | 38 | data Alteration = Modify Entity SequenceValue |
40 | | Override Entity Integer | 39 | | Override Entity SequenceValue |
41 | | Drop Entity | 40 | | Drop Entity |
42 | | Insert Entity Integer | 41 | | Insert Entity SequenceValue |
43 | | Rename Entity Entity | 42 | | Rename Entity Entity |
44 | deriving (Show) | 43 | deriving (Show) |
45 | 44 | ||
46 | data SequenceState = SequenceState | 45 | type Sequence = MaxPQueue SequenceValue Entity |
47 | { _queue :: MaxPQueue Integer Entity -- Current state | 46 | |
48 | , _history :: Seq (Alteration, Maybe Comment) -- Most recent last | 47 | type History = Seq (Alteration, Comment) |
49 | } | 48 | |
50 | deriving (Show) | 49 | type SequenceM m = (MonadWriter History m, MonadState Sequence m, MonadIO m) |
51 | makeLenses ''SequenceState | 50 | |
52 | 51 | instance MonadState s m => MonadState s (InputT m) where | |
53 | instance Default SequenceState where | 52 | get = lift get |
54 | def = SequenceState | 53 | put = lift . put |
55 | { _queue = MaxPQueue.empty | 54 | state = lift . state |
56 | , _history = Seq.empty | 55 | |
57 | } | 56 | instance Default (MaxPQueue k v) where |
57 | def = MaxPQueue.empty | ||