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/Formula.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/Sequence/Formula.hs') 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