From 20969c7edca686672589a7f5fae14e93a688778a Mon Sep 17 00:00:00 2001 From: Yoo Chung Date: Thu, 30 May 2024 20:37:43 -0400 Subject: [PATCH] Turn off warnings for existing uses of head or tail, or remove their use. Allows building with 9.8.2. --- bench/Problems/P61Bench.hs | 2 ++ ninetynine.cabal | 2 +- src/Problems/Graphs.hs | 2 ++ src/Problems/P50.hs | 2 ++ src/Problems/P91.hs | 2 ++ src/Problems/P98.hs | 2 ++ src/Problems/P99.hs | 1 + src/Solutions/P10.hs | 2 ++ src/Solutions/P11.hs | 2 ++ src/Solutions/P36.hs | 2 ++ src/Solutions/P44.hs | 2 ++ src/Solutions/P50.hs | 2 ++ src/Solutions/P79.hs | 10 ++++++---- src/Solutions/P82.hs | 2 ++ src/Solutions/P84.hs | 2 ++ src/Solutions/P85.hs | 2 ++ src/Solutions/P91.hs | 2 ++ src/Solutions/P92.hs | 1 + src/Solutions/P97.hs | 2 ++ src/Solutions/P98.hs | 2 ++ src/Solutions/P99.hs | 9 +++++++-- test/Problems/P08Spec.hs | 2 ++ test/Problems/P09Spec.hs | 2 ++ test/Problems/P10Spec.hs | 2 ++ test/Problems/P11Spec.hs | 2 ++ test/Problems/P19Spec.hs | 2 ++ test/Problems/P23Spec.hs | 2 ++ test/Problems/P24Spec.hs | 2 ++ test/Problems/P25Spec.hs | 2 ++ test/Problems/P38Spec.hs | 2 ++ test/Problems/P81Spec.hs | 2 ++ test/Problems/P82Spec.hs | 2 ++ test/Problems/P87Spec.hs | 2 ++ test/Problems/P88Spec.hs | 2 ++ test/Problems/P91Spec.hs | 2 ++ test/Problems/P97Spec.hs | 2 ++ test/Problems/P98Spec.hs | 2 ++ test/Problems/P99Spec.hs | 3 ++- 38 files changed, 82 insertions(+), 8 deletions(-) diff --git a/bench/Problems/P61Bench.hs b/bench/Problems/P61Bench.hs index a93b00c..05924b9 100644 --- a/bench/Problems/P61Bench.hs +++ b/bench/Problems/P61Bench.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2021 Yoo Chung License: GPL-3.0-or-later diff --git a/ninetynine.cabal b/ninetynine.cabal index 0da43a9..8a6ac15 100644 --- a/ninetynine.cabal +++ b/ninetynine.cabal @@ -21,7 +21,7 @@ homepage: https://ninetynine.haskell.chungyc.org/ bug-reports: https://github.com/chungyc/ninetynine/issues author: Yoo Chung maintainer: dev@chungyc.org -copyright: Copyright (C) 2023 Yoo Chung +copyright: Copyright (C) 2024 Yoo Chung license: GPL-3.0-or-later license-file: LICENSE build-type: Simple diff --git a/src/Problems/Graphs.hs b/src/Problems/Graphs.hs index 4fa6f51..e8bcb50 100644 --- a/src/Problems/Graphs.hs +++ b/src/Problems/Graphs.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Supporting definitions for graph problems Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Problems/P50.hs b/src/Problems/P50.hs index b099a54..3c7fa2e 100644 --- a/src/Problems/P50.hs +++ b/src/Problems/P50.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Huffman codes Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Problems/P91.hs b/src/Problems/P91.hs index d979685..bb1cd05 100644 --- a/src/Problems/P91.hs +++ b/src/Problems/P91.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Knight's tour Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Problems/P98.hs b/src/Problems/P98.hs index c4bc5f3..69a09cb 100644 --- a/src/Problems/P98.hs +++ b/src/Problems/P98.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Nonograms Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Problems/P99.hs b/src/Problems/P99.hs index 0c6219f..8bd1e9d 100644 --- a/src/Problems/P99.hs +++ b/src/Problems/P99.hs @@ -12,6 +12,7 @@ import Problems.Crosswords import qualified Solutions.P99 as Solution -- $setup +-- >>> :set -Wno-x-partial -Wno-unrecognised-warning-flags -- >>> import Data.Maybe (fromJust) -- >>> import Problems.Crosswords diff --git a/src/Solutions/P10.hs b/src/Solutions/P10.hs index 6af597c..7f10555 100644 --- a/src/Solutions/P10.hs +++ b/src/Solutions/P10.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Run-length encoding of a list Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P11.hs b/src/Solutions/P11.hs index 6977a41..70e7da4 100644 --- a/src/Solutions/P11.hs +++ b/src/Solutions/P11.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Modified run-length encoding Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P36.hs b/src/Solutions/P36.hs index 1f77f5b..c3c8234 100644 --- a/src/Solutions/P36.hs +++ b/src/Solutions/P36.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: List of prime factors and their multiplicities Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P44.hs b/src/Solutions/P44.hs index 138ae4f..a4d085d 100644 --- a/src/Solutions/P44.hs +++ b/src/Solutions/P44.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Gaussian primes Copyright: Copyright (C) 2022 Yoo Chung diff --git a/src/Solutions/P50.hs b/src/Solutions/P50.hs index 00ebca8..d49f624 100644 --- a/src/Solutions/P50.hs +++ b/src/Solutions/P50.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Huffman codes Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P79.hs b/src/Solutions/P79.hs index 2623624..9c462e2 100644 --- a/src/Solutions/P79.hs +++ b/src/Solutions/P79.hs @@ -8,7 +8,7 @@ Some solutions to "Problems.P79" of Ninety-Nine Haskell "Problems". -} module Solutions.P79 (calculatePostfix) where -import Control.Monad (guard, mzero) +import Control.Monad (mzero) import Control.Monad.Identity import Control.Monad.State import Control.Monad.Trans.Maybe @@ -70,6 +70,8 @@ push x = modify (x:) pop :: Calculation Integer pop = do xs <- get - guard $ not $ null xs - put $ tail xs - return $ head xs + case xs of + [] -> mzero + (x:xs') -> do + put xs' + return x diff --git a/src/Solutions/P82.hs b/src/Solutions/P82.hs index d504908..f529d5f 100644 --- a/src/Solutions/P82.hs +++ b/src/Solutions/P82.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Cycles with a given vertex Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P84.hs b/src/Solutions/P84.hs index 3ddf342..e27974a 100644 --- a/src/Solutions/P84.hs +++ b/src/Solutions/P84.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Construct minimum spanning tree Copyright: Copyright (C) 2021 Yoo Chung diff --git a/src/Solutions/P85.hs b/src/Solutions/P85.hs index 431b60c..e43f844 100644 --- a/src/Solutions/P85.hs +++ b/src/Solutions/P85.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Graph isomorphism Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Solutions/P91.hs b/src/Solutions/P91.hs index e0bf605..1198591 100644 --- a/src/Solutions/P91.hs +++ b/src/Solutions/P91.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Knight's tour Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Solutions/P92.hs b/src/Solutions/P92.hs index ed7e514..26ead50 100644 --- a/src/Solutions/P92.hs +++ b/src/Solutions/P92.hs @@ -1,4 +1,5 @@ {-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-} +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} {- | Description: Graceful tree labeling diff --git a/src/Solutions/P97.hs b/src/Solutions/P97.hs index eaacbb8..ca17ac7 100644 --- a/src/Solutions/P97.hs +++ b/src/Solutions/P97.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Sudoku Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Solutions/P98.hs b/src/Solutions/P98.hs index 7105b47..f20cfa8 100644 --- a/src/Solutions/P98.hs +++ b/src/Solutions/P98.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {- | Description: Nonograms Copyright: Copyright (C) 2023 Yoo Chung diff --git a/src/Solutions/P99.hs b/src/Solutions/P99.hs index 7574a03..8d6f4f2 100644 --- a/src/Solutions/P99.hs +++ b/src/Solutions/P99.hs @@ -153,7 +153,9 @@ findSites g orient = concatMap (evalState find . initial) $ zip [0..] g , fssChars = [] , fssLocs = [] } - step = modify $ \st -> st { fssSpots = tail $ fssSpots st + step = modify $ \st -> st { fssSpots = case fssSpots st of + [] -> error "no more spots" + (_:xs) -> xs , fssPos = 1 + fssPos st } @@ -289,7 +291,10 @@ guess' :: RandomGen g => Partial -> State g (Maybe Partial) guess' p = do tiebreakers <- do gen <- state split return (randoms gen :: [Int]) - let siteIndex = snd $ head $ sortOn count $ zip tiebreakers $ Map.keys $ candidates p + let sitePicks = sortOn count $ zip tiebreakers $ Map.keys $ candidates p + let siteIndex = snd $ case sitePicks of + (x:_) -> x + [] -> error "no more sites" wordList <- state $ randomPermute $ candidates p ! siteIndex state $ tryGuesses p siteIndex wordList where diff --git a/test/Problems/P08Spec.hs b/test/Problems/P08Spec.hs index 4461238..9d5150b 100644 --- a/test/Problems/P08Spec.hs +++ b/test/Problems/P08Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P09Spec.hs b/test/Problems/P09Spec.hs index dfe6270..6d2defd 100644 --- a/test/Problems/P09Spec.hs +++ b/test/Problems/P09Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P10Spec.hs b/test/Problems/P10Spec.hs index d20287b..89d3775 100644 --- a/test/Problems/P10Spec.hs +++ b/test/Problems/P10Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P11Spec.hs b/test/Problems/P11Spec.hs index edb1687..136d229 100644 --- a/test/Problems/P11Spec.hs +++ b/test/Problems/P11Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P19Spec.hs b/test/Problems/P19Spec.hs index 4982248..c5eeafb 100644 --- a/test/Problems/P19Spec.hs +++ b/test/Problems/P19Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P23Spec.hs b/test/Problems/P23Spec.hs index 042a992..d6d19a8 100644 --- a/test/Problems/P23Spec.hs +++ b/test/Problems/P23Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P24Spec.hs b/test/Problems/P24Spec.hs index abcd0c2..b8542fb 100644 --- a/test/Problems/P24Spec.hs +++ b/test/Problems/P24Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P25Spec.hs b/test/Problems/P25Spec.hs index 9c55620..189f2a9 100644 --- a/test/Problems/P25Spec.hs +++ b/test/Problems/P25Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P38Spec.hs b/test/Problems/P38Spec.hs index 5970edc..9ae84c2 100644 --- a/test/Problems/P38Spec.hs +++ b/test/Problems/P38Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P81Spec.hs b/test/Problems/P81Spec.hs index f29f71f..87b4a04 100644 --- a/test/Problems/P81Spec.hs +++ b/test/Problems/P81Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P82Spec.hs b/test/Problems/P82Spec.hs index 738405c..fb79d54 100644 --- a/test/Problems/P82Spec.hs +++ b/test/Problems/P82Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P87Spec.hs b/test/Problems/P87Spec.hs index 718285f..ff492ce 100644 --- a/test/Problems/P87Spec.hs +++ b/test/Problems/P87Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P88Spec.hs b/test/Problems/P88Spec.hs index 41a2afa..e87a1d2 100644 --- a/test/Problems/P88Spec.hs +++ b/test/Problems/P88Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P91Spec.hs b/test/Problems/P91Spec.hs index ad5e70b..0c47538 100644 --- a/test/Problems/P91Spec.hs +++ b/test/Problems/P91Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P97Spec.hs b/test/Problems/P97Spec.hs index f99d689..0afc6c0 100644 --- a/test/Problems/P97Spec.hs +++ b/test/Problems/P97Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P98Spec.hs b/test/Problems/P98Spec.hs index f40c434..4c05336 100644 --- a/test/Problems/P98Spec.hs +++ b/test/Problems/P98Spec.hs @@ -1,3 +1,5 @@ +{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-} + {-| Copyright: Copyright (C) 2023 Yoo Chung License: GPL-3.0-or-later diff --git a/test/Problems/P99Spec.hs b/test/Problems/P99Spec.hs index f4ce086..b38f23a 100644 --- a/test/Problems/P99Spec.hs +++ b/test/Problems/P99Spec.hs @@ -135,7 +135,8 @@ addToSolution g (w,x,y,False) -- I.e., we don't like sites that we didn't add ourselves. -- Reject grids which have 2x2 blank areas. isValid :: [[Maybe Char]] -> Bool -isValid g = all isValidRows $ zip g $ tail g +isValid [] = False +isValid g@(_:gs) = all isValidRows $ zip g gs where isValidRows ([], []) = True isValidRows (Just _ : Just _ : _, Just _ : Just _ : _) = False