summaryrefslogtreecommitdiff
path: root/src/Types.hs
blob: 2dff0f0faa3b93de6ea98cb5a593e58e16f109a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{-# LANGUAGE TemplateHaskell, OverloadedStrings #-}

module Types
       ( Entity(..)
       , showEntity
       , Comment
       , Alteration(..)
       , SequenceState, queue, history
       ) where

import           Data.PQueue.Prio.Max (MaxPQueue)
import qualified Data.PQueue.Prio.Max as MaxPQueue

import           Data.Sequence (Seq)
import qualified Data.Sequence as Seq

import           Data.Monoid (Monoid(..), (<>))

import           Control.Monad.State.Lazy (MonadState)
import           Control.Monad.IO.Class (MonadIO)

import           Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text

import           Control.Lens.TH

import           Data.Default.Class

data Entity = Entity Text (Maybe Integer)
            deriving (Eq, Ord, Show)

showEntity :: Entity -> Text
showEntity (Entity t Nothing) = t
showEntity (Entity t (Just n)) = t <> " " <> (Text.pack $ show n)

type Comment = Text

data Alteration = Modify Entity Integer
                | Override Entity Integer
                | Drop Entity
                | Insert Entity Integer
                | Rename Entity Entity
                deriving (Show)

data SequenceState = SequenceState
                     { _queue   :: MaxPQueue Integer Entity -- Current state
                     , _history :: Seq (Alteration, Maybe Comment) -- Most recent last
                     }
                   deriving (Show)
makeLenses ''SequenceState

instance Default SequenceState where
  def = SequenceState
        { _queue   = MaxPQueue.empty
        , _history = Seq.empty
        }