From 048779ac250b0cb463839edd8f46d9785fb3f9e5 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 4 Jun 2016 18:06:12 +0200 Subject: quotients of random events --- src/Sequence/Formula.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Sequence/Formula.hs b/src/Sequence/Formula.hs index fc61efb..66672a2 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, Formula + ( FormulaM, Formula, quot' , evalFormula , val , d, z @@ -9,9 +9,8 @@ module Sequence.Formula import Control.Lens import Data.Data.Lens -import Data.Data (Data) -import Data.Typeable (Typeable) +import Control.Monad import Control.Monad.Except import Control.Monad.Reader import Numeric.Probability.Game.Event @@ -28,7 +27,7 @@ import Data.Maybe type FormulaM input a = ReaderT input (ExceptT (Question input) EventM) a -type Formula input = Formulam input Int +type Formula input = FormulaM input Int data Question input = Question { answer :: Traversal' input (Formula input) @@ -46,6 +45,8 @@ instance Integral a => Num (FormulaM input a) where sum <$> replicateM (fromIntegral n) y fromInteger = return . fromInteger +quot' :: Integral a => FormulaM input a -> FormulaM input a -> FormulaM input a +quot' = liftM2 quot askQuestion :: MonadIO m => input -> (Question input) -> m input askQuestion input q@(Question{..}) = flip (set answer) input . maybe (throwError q) return <$> askQ prompt (join . fmap readMaybe) -- cgit v1.2.3