Skip to content

Commit

Permalink
Use NonEmpty from semigroups
Browse files Browse the repository at this point in the history
  • Loading branch information
bartavelle committed May 15, 2014
1 parent 0334a6d commit 0bdcf97
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
3 changes: 2 additions & 1 deletion 7startups.cabal
Expand Up @@ -40,7 +40,8 @@ library
random == 1.*,
split == 0.2.*,
ansi-wl-pprint == 0.6.*,
operational == 0.2.*
operational == 0.2.*,
semigroups == 0.13.*
-- hs-source-dirs:
default-language: Haskell2010

Expand Down
11 changes: 2 additions & 9 deletions Startups/GameTypes.hs
Expand Up @@ -20,6 +20,7 @@ import qualified Data.Map.Strict as M
import Control.Monad.Operational
import Control.Monad.State.Strict
import Control.Monad.Error
import Data.List.NonEmpty
import Control.Applicative
import System.Random

Expand Down Expand Up @@ -64,16 +65,8 @@ data PlayerAction = PlayerAction ActionType Card
data ActionType = Play | Drop | BuildCompany
deriving Eq

-- | Some types for non empty lists
data NonEmpty a = NonEmpty a [a]

_NonEmpty :: Prism' [a] (NonEmpty a)
_NonEmpty = prism fromNonEmpty toNonEmpty
where
fromNonEmpty (NonEmpty x xs) = x : xs
toNonEmpty l = case l of
[] -> Left l
(x:xs) -> Right (NonEmpty x xs)
_NonEmpty = prism' toList nonEmpty

-- | This describe the capabilities needed to write the rules, when no
-- interaction with the player is required.
Expand Down
1 change: 1 addition & 0 deletions Startups/Interpreter.hs
Expand Up @@ -8,6 +8,7 @@ import Startups.GameTypes
import qualified Data.Map.Strict as M
import Control.Monad.Operational
import Control.Monad.State.Strict
import Data.List.NonEmpty

data OperationDict m = OperationDict { _doPlayerDecision :: Age -> Turn -> PlayerId -> NonEmpty Card -> GameState -> m (PlayerAction, Exchange)
, _doAskCard :: Age -> PlayerId -> NonEmpty Card -> GameState -> Message -> m Card
Expand Down

0 comments on commit 0bdcf97

Please sign in to comment.