Skip to content

Commit cf4036f

Browse files
committed
Fix builds for GHC 9.10+
1 parent 91e47fd commit cf4036f

File tree

5 files changed

+50
-50
lines changed

5 files changed

+50
-50
lines changed

ch05/weapons.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
{-# LANGUAGE ScopedTypeVariables #-}
2+
{-# LANGUAGE FlexibleContexts #-}
3+
{-# LANGUAGE UndecidableInstances #-}
14
import Data.List (group, sort)
25
import Control.Monad
36
import Control.Monad.State
47
import System.Random
5-
import System.Random.Stateful (uniformRM, uniformM)
8+
import System.Random.Stateful
69

710
data Weapon = Rock | Paper | Scissors
811
deriving (Show, Bounded, Enum, Eq)
@@ -19,11 +22,10 @@ winner (w1, w2)
1922
| otherwise = Second
2023

2124
instance UniformRange Weapon where
22-
uniformRM (lo, hi) rng = do
23-
res <- uniformRM (fromEnum lo :: Int, fromEnum hi) rng
24-
pure $ toEnum res
25+
uniformRM (lo, hi) g = toEnum <$> uniformRM (fromEnum lo, fromEnum hi) g
26+
isInRange (lo, hi) x = fromEnum x >= fromEnum lo && fromEnum x <= fromEnum hi
2527

26-
instance Uniform Weapon where
28+
instance UniformRange Weapon => Uniform Weapon where
2729
uniformM rng = uniformRM (minBound, maxBound) rng
2830

2931
randomWeapon :: State StdGen Weapon

ch07/logging.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ popAndLog :: LoggingT (StateT [Int] IO) ()
1010
popAndLog = do
1111
_:xs <- lift get
1212
lift (put xs)
13-
$logDebug ("***" <> (pack $ show xs) <> "***")
13+
$logDebug ("***" <> (pack $ Prelude.show xs) <> "***")
1414

1515
logStateEx :: LoggingT (StateT [Int] IO) Int
1616
logStateEx = do

hid-examples.cabal

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cabal-version: 2.0
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: 3a83185a1a255aa08e871ef0a8fcabde2c05975f2556603454bce153bad1d11f
7+
-- hash: df9bdff20c7b93fa747ba6e542d129c1a39765b56d9e6b7e3081327b44667265
88

99
name: hid-examples
1010
version: 0.5
@@ -168,7 +168,7 @@ library rpc-lib
168168
, mtl >=2.0 && <2.4
169169
, network >=2.8 && <3.3
170170
, network-simple >=0.4.5 && <0.5
171-
, template-haskell >=2.13 && <2.23
171+
, template-haskell >=2.13 && <2.24
172172
default-language: Haskell2010
173173

174174
library shunting-yard
@@ -362,7 +362,7 @@ executable covid
362362
attoparsec >=0.13 && <0.15
363363
, base >=4.12 && <5
364364
, bytestring >=0.10 && <0.13
365-
, containers >=0.5 && <0.8
365+
, containers >=0.5 && <0.9
366366
, lens >=4.17 && <5.4
367367
, resourcet >=1.2 && <1.4
368368
, streaming >=0.2.2 && <0.4
@@ -403,7 +403,7 @@ executable dicegame
403403
build-depends:
404404
base >=4.12 && <5
405405
, mtl >=2.0 && <2.4
406-
, random ==1.2.*
406+
, random >=1.2 && <1.4
407407
default-language: Haskell2010
408408

409409
executable div
@@ -453,7 +453,7 @@ executable door-gen
453453
build-depends:
454454
base >=4.12 && <5
455455
, singletons ==3.0.*
456-
, singletons-base >=3.0 && <3.5
456+
, singletons-base >=3.0 && <3.6
457457
default-language: Haskell2010
458458

459459
executable dots
@@ -489,7 +489,7 @@ executable dots-async-cancel
489489
build-depends:
490490
async >=2.0 && <2.3
491491
, base >=4.12 && <5
492-
, random ==1.2.*
492+
, random >=1.2 && <1.4
493493
default-language: Haskell2010
494494

495495
executable dots-async-interrupted
@@ -543,7 +543,7 @@ executable du
543543
build-depends:
544544
base >=4.12 && <5
545545
, directory ==1.3.*
546-
, extra >=1.5 && <1.8
546+
, extra >=1.5 && <1.9
547547
, filepath >=1.4.1 && <1.6
548548
, mtl >=2.0 && <2.4
549549
, optparse-applicative >=0.14 && <0.19
@@ -582,7 +582,7 @@ executable elevator
582582
, fin >=0.1 && <0.4
583583
, mtl >=2.0 && <2.4
584584
, singletons ==3.0.*
585-
, singletons-base >=3.0 && <3.5
585+
, singletons-base >=3.0 && <3.6
586586
default-language: Haskell2010
587587

588588
executable evalrpn1
@@ -654,7 +654,7 @@ executable filecount
654654
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-error=unrecognised-warning-flags
655655
build-depends:
656656
base >=4.12 && <5
657-
, extra >=1.5 && <1.8
657+
, extra >=1.5 && <1.9
658658
default-language: Haskell2010
659659

660660
executable gcd
@@ -775,7 +775,7 @@ executable hello-th
775775
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-error=unrecognised-warning-flags
776776
build-depends:
777777
base >=4.12 && <5
778-
, template-haskell >=2.13 && <2.23
778+
, template-haskell >=2.13 && <2.24
779779
default-language: Haskell2010
780780

781781
executable interleaving
@@ -907,7 +907,7 @@ executable mstr-literals
907907
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-error=unrecognised-warning-flags -Wno-missing-signatures -Wno-incomplete-patterns
908908
build-depends:
909909
base >=4.12 && <5
910-
, template-haskell >=2.13 && <2.23
910+
, template-haskell >=2.13 && <2.24
911911
default-language: Haskell2010
912912

913913
executable mvar-deadlocks
@@ -1091,7 +1091,7 @@ executable predicates
10911091
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-error=unrecognised-warning-flags -Wno-missing-signatures -Wno-incomplete-patterns
10921092
build-depends:
10931093
base >=4.12 && <5
1094-
, template-haskell >=2.13 && <2.23
1094+
, template-haskell >=2.13 && <2.24
10951095
default-language: Haskell2010
10961096

10971097
executable prefix-postfix
@@ -1117,7 +1117,7 @@ executable projectors
11171117
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-error=unrecognised-warning-flags
11181118
build-depends:
11191119
base >=4.12 && <5
1120-
, template-haskell >=2.13 && <2.23
1120+
, template-haskell >=2.13 && <2.24
11211121
default-language: Haskell2010
11221122

11231123
executable pub-sub
@@ -1313,7 +1313,7 @@ executable sumtab
13131313
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-error=unrecognised-warning-flags
13141314
build-depends:
13151315
base >=4.12 && <5
1316-
, extra >=1.5 && <1.8
1316+
, extra >=1.5 && <1.9
13171317
, streaming >=0.2.2 && <0.4
13181318
, text >=1.2 && <2.2
13191319
, text-show >=3.0 && <4
@@ -1433,7 +1433,7 @@ executable type-families
14331433
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-error=unrecognised-warning-flags -Wno-type-defaults
14341434
build-depends:
14351435
base >=4.12 && <5
1436-
, containers >=0.5 && <0.8
1436+
, containers >=0.5 && <0.9
14371437
default-language: Haskell2010
14381438

14391439
executable type-lits
@@ -1557,7 +1557,7 @@ executable wait-completion
15571557
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-error=unrecognised-warning-flags -threaded
15581558
build-depends:
15591559
base >=4.12 && <5
1560-
, random ==1.2.*
1560+
, random >=1.2 && <1.4
15611561
default-language: Haskell2010
15621562

15631563
executable weapons
@@ -1572,7 +1572,7 @@ executable weapons
15721572
build-depends:
15731573
base >=4.12 && <5
15741574
, mtl >=2.0 && <2.4
1575-
, random ==1.2.*
1575+
, random >=1.2 && <1.4
15761576
default-language: Haskell2010
15771577

15781578
test-suite expr-simple-test
@@ -1598,7 +1598,7 @@ test-suite iplookup-doctest
15981598
ghc-options: -Wall -Werror -Wcompat -Widentities -Wincomplete-uni-patterns -Wincomplete-record-updates -Wno-unused-top-binds -Wno-orphans -Wno-error=unrecognised-warning-flags
15991599
build-depends:
16001600
base >=4.12 && <5
1601-
, doctest >=0.12 && <0.23
1601+
, doctest >=0.12 && <0.25
16021602
, split ==0.2.*
16031603
default-language: Haskell2010
16041604

@@ -1638,7 +1638,7 @@ test-suite radar-test
16381638
build-depends:
16391639
base >=4.12 && <5
16401640
, radar-lib
1641-
, random ==1.2.*
1641+
, random >=1.2 && <1.4
16421642
default-language: Haskell2010
16431643

16441644
test-suite shunting-yard-test

package.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ executables:
155155
main: weapons.hs
156156
dependencies:
157157
- mtl >=2.0 && <2.4
158-
- random >=1.2 && <1.3
158+
- random >=1.2 && <1.4
159159
prefix-postfix:
160160
source-dirs: expr
161161
main: prefix-postfix.hs
@@ -170,15 +170,15 @@ executables:
170170
main: dicegame.hs
171171
dependencies:
172172
- mtl >=2.0 && <2.4
173-
- random >=1.2 && <1.3
173+
- random >=1.2 && <1.4
174174
ioref:
175175
source-dirs: ch05
176176
main: ioref.hs
177177
filecount:
178178
source-dirs: ch05
179179
main: filecount.hs
180180
dependencies:
181-
- extra >=1.5 && <1.8
181+
- extra >=1.5 && <1.9
182182
stref:
183183
source-dirs: ch05
184184
main: stref.hs
@@ -228,7 +228,7 @@ executables:
228228
- optparse-applicative >= 0.14 && < 0.19
229229
- text >=1.2 && <2.2
230230
- text-show >=3.0 && <4
231-
- extra >=1.5 && <1.8
231+
- extra >=1.5 && <1.9
232232
default-extensions:
233233
- RecordWildCards
234234
- NamedFieldPuns
@@ -368,7 +368,7 @@ executables:
368368
ghc-options:
369369
-Wno-type-defaults
370370
dependencies:
371-
- containers >= 0.5 && < 0.8
371+
- containers >= 0.5 && < 0.9
372372
dynvalues-gadt:
373373
main: ch11/dynvalues-gadt.hs
374374
other-extensions:
@@ -428,19 +428,19 @@ executables:
428428
main: Main.hs
429429
other-modules: [ Hello ]
430430
dependencies:
431-
- template-haskell >=2.13 && <2.23
431+
- template-haskell >=2.13 && <2.24
432432
projectors:
433433
source-dirs: ch12/th/projectors/
434434
main: Main.hs
435435
other-modules: [ Projectors ]
436436
dependencies:
437-
- template-haskell >=2.13 && <2.23
437+
- template-haskell >=2.13 && <2.24
438438
predicates:
439439
source-dirs: ch12/th/predicates/
440440
main: Main.hs
441441
other-modules: [ Predicates ]
442442
dependencies:
443-
- template-haskell >=2.13 && <2.23
443+
- template-haskell >=2.13 && <2.24
444444
ghc-options:
445445
- -Wno-missing-signatures
446446
- -Wno-incomplete-patterns
@@ -449,7 +449,7 @@ executables:
449449
main: Main.hs
450450
other-modules: [ Str ]
451451
dependencies:
452-
- template-haskell >=2.13 && <2.23
452+
- template-haskell >=2.13 && <2.24
453453
ghc-options:
454454
- -Wno-missing-signatures
455455
- -Wno-incomplete-patterns
@@ -527,7 +527,7 @@ executables:
527527
- StandaloneDeriving
528528
dependencies:
529529
- singletons >= 3.0 && < 3.1
530-
- singletons-base >= 3.0 && < 3.5
530+
- singletons-base >= 3.0 && < 3.6
531531
ghc-options:
532532
- -Wno-unticked-promoted-constructors
533533
elevator:
@@ -543,7 +543,7 @@ executables:
543543
- fin >= 0.1 && < 0.4
544544
- dec >= 0.0.3 && < 0.1
545545
- singletons >= 3.0 && < 3.1
546-
- singletons-base >= 3.0 && < 3.5
546+
- singletons-base >= 3.0 && < 3.6
547547
- mtl >=2.0 && <2.4
548548
ghc-options:
549549
- -Wno-unticked-promoted-constructors
@@ -556,7 +556,7 @@ executables:
556556
main: ch14/sumtab.hs
557557
dependencies:
558558
- streaming >=0.2.2 && <0.4
559-
- extra >=1.5 && <1.8
559+
- extra >=1.5 && <1.9
560560
- text >=1.2 && <2.2
561561
- text-show >=3.0 && <4
562562
chars:
@@ -592,7 +592,7 @@ executables:
592592
- time >=1.8 && <1.15
593593
- text >=1.2 && <2.2
594594
- text-show >=3.0 && <4
595-
- containers >= 0.5 && < 0.8
595+
- containers >= 0.5 && < 0.9
596596
- lens >= 4.17 && < 5.4
597597
- streaming-utils >=0.2 && <0.3
598598
- streaming-bytestring >=0.1.7 && <0.4
@@ -695,7 +695,7 @@ executables:
695695
ghc-options: -threaded
696696
dependencies:
697697
- async >= 2.0 && < 2.3
698-
- random >=1.2 && <1.3
698+
- random >=1.2 && <1.4
699699
dots-async-interrupted:
700700
main: ch16/dots-async-interrupted.hs
701701
ghc-options: -threaded
@@ -710,7 +710,7 @@ executables:
710710
main: ch16/wait-completion.hs
711711
ghc-options: -threaded
712712
dependencies:
713-
- random >=1.2 && <1.3
713+
- random >=1.2 && <1.4
714714
sum-numbers:
715715
main: ch16/sum-numbers.hs
716716
dependencies:
@@ -831,7 +831,7 @@ internal-libraries:
831831
- crypton-connection >= 0.3 && <0.5
832832
- network-simple >=0.4.5 && <0.5
833833
- exceptions >= 0.10 && < 0.11
834-
- template-haskell >= 2.13 && <2.23
834+
- template-haskell >= 2.13 && <2.24
835835
- haskell-src-exts >= 1.20 && <1.24
836836
- haskell-src-meta >= 0.6 && < 0.9
837837
tests:
@@ -842,7 +842,7 @@ tests:
842842
other-modules: []
843843
dependencies:
844844
- radar-lib
845-
- random >=1.2 && <1.3
845+
- random >=1.2 && <1.4
846846
expr-simple-test:
847847
source-dirs: tests/expr
848848
main: Test1.hs
@@ -879,7 +879,7 @@ tests:
879879
iplookup-doctest:
880880
main: tests/iplookup-doctest/Doctests.hs
881881
dependencies:
882-
- doctest >= 0.12 && < 0.23
882+
- doctest >= 0.12 && < 0.25
883883
- split >= 0.2 && < 0.3
884884

885885
benchmarks:

tests/radar/Test.hs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@ import System.Exit (exitFailure)
55
import Data.List (sort, nub)
66
import Control.Monad (replicateM, when)
77
import System.Random
8-
import System.Random.Stateful (uniformRM, uniformM)
8+
import System.Random.Stateful
99

1010
import Radar
1111

1212
instance UniformRange Turn where
13-
uniformRM (lo, hi) rng = do
14-
res <- uniformRM (fromEnum lo :: Int, fromEnum hi) rng
15-
pure $ toEnum res
13+
uniformRM (lo, hi) g = toEnum <$> uniformRM (fromEnum lo, fromEnum hi) g
14+
isInRange (lo, hi) x = fromEnum x >= fromEnum lo && fromEnum x <= fromEnum hi
1615

1716
instance Uniform Turn where
1817
uniformM rng = uniformRM (minBound, maxBound) rng
1918

2019
instance UniformRange Direction where
21-
uniformRM (lo, hi) rng = do
22-
res <- uniformRM (fromEnum lo :: Int, fromEnum hi) rng
23-
pure $ toEnum res
20+
uniformRM (lo, hi) g = toEnum <$> uniformRM (fromEnum lo, fromEnum hi) g
21+
isInRange (lo, hi) x = fromEnum x >= fromEnum lo && fromEnum x <= fromEnum hi
2422

2523
instance Uniform Direction where
2624
uniformM rng = uniformRM (minBound, maxBound) rng

0 commit comments

Comments
 (0)