diff --git a/examples/Cabbage.lhs b/examples/Cabbage.lhs index a28096f..27d0267 100644 --- a/examples/Cabbage.lhs +++ b/examples/Cabbage.lhs @@ -83,8 +83,14 @@ When the starting side becomes empty, the farmer succeeds. A straightforward implementation to solve the problem could use the list monad, trying all possible solutions and +> getFirstSolution :: [Situation] -> Situation +> getFirstSolution ss = +> case ss of +> s:_ -> s +> [] -> error "No solutions" +> > solution1 :: Situation -> solution1 = head $ solutions' initial +> solution1 = getFirstSolution $ solutions' initial > where > solutions' a = if success a > then return a diff --git a/examples/NewtonCoiter.lhs b/examples/NewtonCoiter.lhs index 9095b5c..eb93611 100644 --- a/examples/NewtonCoiter.lhs +++ b/examples/NewtonCoiter.lhs @@ -7,9 +7,11 @@ to find zeroes of a function is one such algorithm. > {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-} > module Main where -> import Control.Comonad.Trans.Coiter > import Control.Comonad.Env +> import Control.Comonad.Trans.Coiter +> import Control.Comonad.Trans.Env (lowerEnvT) > import Data.Foldable (toList, find) +> import Data.Functor.Identity (Identity(..)) > data Function = Function { > -- Function to find zeroes of @@ -75,7 +77,8 @@ future and check if the result improves at all. > estimateOutlook :: Int -> Solution Result -> Outlook > estimateOutlook sampleSize solution = -> let sample = map ferror $ take sampleSize $ tail $ toList solution in +> let sample = map ferror $ take sampleSize $ toList $ snd $ runIdentity $ +> lowerEnvT $ runCoiterT solution in > let result' = extract solution in > Outlook { result = result', > progress = ferror result' > minimum sample }