From 38f4f07e18623c8875f8253f8289a73448682c85 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Tue, 1 Aug 2023 14:16:47 -0400 Subject: [PATCH] free-examples: Fix some -Wx-partial warnings These were uncovered by GHC 9.8, where -Wx-partial is included in -Wall. --- examples/Cabbage.lhs | 8 +++++++- examples/NewtonCoiter.lhs | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) 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 }