From c1fe5811daf9780bc4a822776c3eb5c920941d45 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 4 Jun 2016 01:16:16 +0200 Subject: cleanup --- src/Sequence/Contact/Types.hs | 6 +++--- src/Sequence/Formula.hs | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src/Sequence') diff --git a/src/Sequence/Contact/Types.hs b/src/Sequence/Contact/Types.hs index 815bd4e..b63b369 100644 --- a/src/Sequence/Contact/Types.hs +++ b/src/Sequence/Contact/Types.hs @@ -55,7 +55,7 @@ data Stats = Prop , _sMaxVitality , _sSeqVal , _sPainTolerance - , _sFatigueTolerance :: FormulaM Stats Int + , _sFatigueTolerance :: Formula Stats } | Quadruped { _sAStrength @@ -78,7 +78,7 @@ data Stats = Prop , _sMaxVitality , _sSeqVal , _sPainTolerance - , _sFatigueTolerance :: FormulaM Stats Int + , _sFatigueTolerance :: Formula Stats } | Dolphin { _sAStrength @@ -101,7 +101,7 @@ data Stats = Prop , _sMaxVitality , _sSeqVal , _sPainTolerance - , _sFatigueTolerance :: FormulaM Stats Int + , _sFatigueTolerance :: Formula Stats } makeLenses ''Stats diff --git a/src/Sequence/Formula.hs b/src/Sequence/Formula.hs index 2a4541f..fc61efb 100644 --- a/src/Sequence/Formula.hs +++ b/src/Sequence/Formula.hs @@ -1,7 +1,7 @@ {-# LANGUAGE RecordWildCards, RankNTypes, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, ViewPatterns, TypeFamilies #-} module Sequence.Formula - ( FormulaM + ( FormulaM, Formula , evalFormula , val , d, z @@ -28,8 +28,10 @@ import Data.Maybe type FormulaM input a = ReaderT input (ExceptT (Question input) EventM) a +type Formula input = Formulam input Int + data Question input = Question - { answer :: Traversal' input (FormulaM input Int) + { answer :: Traversal' input (Formula input) , prompt :: String , keepResult :: Bool } @@ -57,10 +59,10 @@ evalFormula = evalFormula' [] Left q@(Question{..}) -> askQuestion input q >>= flip (evalFormula' $ bool (pure . set answer $ throwError q) mempty keepResult ++ finalChanges) formula Right result -> return (foldr ($) input finalChanges, result) -val :: Integral a => Traversal' input (FormulaM input Int) -> String -> Bool -> FormulaM input Int +val :: Integral a => Traversal' input (Formula input) -> String -> Bool -> Formula input val answer prompt keepResult = preview answer >>= maybe (throwError Question{..}) id --- viewL :: Lens' lInput sInput -> Iso' (FormulaM sInput a) (FormulaM lInput a) +-- viewL :: Lens' lInput sInput -> Prism' (FormulaM sInput a) (FormulaM lInput a) -- viewL lTrav = iso asL asS -- where -- asL small = join $ lift . withExceptT (\Question{..} -> Question{ answer = lTrav . answer . viewL lTrav, .. }) . runReaderT small <$> view lTrav -- cgit v1.2.3