Skip to content

Commit

Permalink
Turn off warnings for using head or tail, or remove their use.
Browse files Browse the repository at this point in the history
Allows building with 9.8.2.
  • Loading branch information
chungyc committed May 31, 2024
1 parent bd33154 commit 592add0
Show file tree
Hide file tree
Showing 39 changed files with 83 additions and 9 deletions.
2 changes: 2 additions & 0 deletions bench/Problems/P61Bench.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2021 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 1 addition & 1 deletion ninetynine.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ homepage: https://ninetynine.haskell.chungyc.org/
bug-reports: https://github.com/chungyc/ninetynine/issues
author: Yoo Chung
maintainer: [email protected]
copyright: Copyright (C) 2023 Yoo Chung
copyright: Copyright (C) 2024 Yoo Chung
license: GPL-3.0-or-later
license-file: LICENSE
build-type: Simple
Expand Down
2 changes: 2 additions & 0 deletions src/Problems/Graphs.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Supporting definitions for graph problems
Copyright: Copyright (C) 2023 Yoo Chung
Expand Down
2 changes: 2 additions & 0 deletions src/Problems/P50.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Huffman codes
Copyright: Copyright (C) 2021 Yoo Chung
Expand Down
2 changes: 2 additions & 0 deletions src/Problems/P91.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Knight's tour
Copyright: Copyright (C) 2023 Yoo Chung
Expand Down
2 changes: 2 additions & 0 deletions src/Problems/P98.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Nonograms
Copyright: Copyright (C) 2021 Yoo Chung
Expand Down
1 change: 1 addition & 0 deletions src/Problems/P99.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Problems.Crosswords
import qualified Solutions.P99 as Solution

-- $setup
-- >>> :set -Wno-x-partial
-- >>> import Data.Maybe (fromJust)
-- >>> import Problems.Crosswords

Expand Down
2 changes: 2 additions & 0 deletions src/Solutions/P10.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Run-length encoding of a list
Copyright: Copyright (C) 2021 Yoo Chung
Expand Down
2 changes: 2 additions & 0 deletions src/Solutions/P11.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Modified run-length encoding
Copyright: Copyright (C) 2021 Yoo Chung
Expand Down
2 changes: 2 additions & 0 deletions src/Solutions/P36.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: List of prime factors and their multiplicities
Copyright: Copyright (C) 2021 Yoo Chung
Expand Down
2 changes: 2 additions & 0 deletions src/Solutions/P44.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Gaussian primes
Copyright: Copyright (C) 2022 Yoo Chung
Expand Down
2 changes: 2 additions & 0 deletions src/Solutions/P50.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Huffman codes
Copyright: Copyright (C) 2021 Yoo Chung
Expand Down
10 changes: 6 additions & 4 deletions src/Solutions/P79.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/Solutions/P82.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Cycles with a given vertex
Copyright: Copyright (C) 2021 Yoo Chung
Expand Down
2 changes: 2 additions & 0 deletions src/Solutions/P84.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Construct minimum spanning tree
Copyright: Copyright (C) 2021 Yoo Chung
Expand Down
2 changes: 2 additions & 0 deletions src/Solutions/P85.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Graph isomorphism
Copyright: Copyright (C) 2023 Yoo Chung
Expand Down
2 changes: 2 additions & 0 deletions src/Solutions/P91.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Knight's tour
Copyright: Copyright (C) 2023 Yoo Chung
Expand Down
1 change: 1 addition & 0 deletions src/Solutions/P92.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-}
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Graceful tree labeling
Expand Down
2 changes: 2 additions & 0 deletions src/Solutions/P97.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Sudoku
Copyright: Copyright (C) 2023 Yoo Chung
Expand Down
2 changes: 2 additions & 0 deletions src/Solutions/P98.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{- |
Description: Nonograms
Copyright: Copyright (C) 2023 Yoo Chung
Expand Down
9 changes: 7 additions & 2 deletions src/Solutions/P99.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies.
resolver: lts-22.23
resolver: nightly-2024-05-29

# User packages to be built.
packages:
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P08Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P09Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P10Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P11Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P19Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P23Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P24Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P25Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P38Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P81Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P82Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P87Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P88Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P91Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P97Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
2 changes: 2 additions & 0 deletions test/Problems/P98Spec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-x-partial #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down
3 changes: 2 additions & 1 deletion test/Problems/P99Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 592add0

Please sign in to comment.