Skip to content

Commit 9f5a41a

Browse files
BodigrimLysxia
authored andcommitted
Avoid partial functions Data.List.init and Data.List.last
This is to comply with haskell/core-libraries-committee#292
1 parent 408eacf commit 9f5a41a

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

benchmarks/haskell/Benchmarks/Micro.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
module Benchmarks.Micro (benchmark) where
44

5+
import qualified Data.List.NonEmpty as NE
56
import qualified Data.Text.Lazy as TL
67
import qualified Data.Text as T
78
import Test.Tasty.Bench (Benchmark, Benchmarkable, bgroup, bcompareWithin, bench, nf)
89

910
benchmark :: Benchmark
1011
benchmark = bgroup "Micro"
1112
[ blinear "lazy-inits--last" 500000 2 0.1 $ \len ->
12-
nf (last . TL.inits) (chunks len)
13+
nf (NE.last . TL.initsNE) (chunks len)
1314
, blinear "lazy-inits--map-take1" 500000 2 0.1 $ \len ->
1415
nf (map (TL.take 1) . TL.inits) (chunks len)
1516
]

src/Data/Text/Lazy/Builder/RealFloat.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{-# LANGUAGE CPP, OverloadedStrings #-}
22
{-# LANGUAGE Trustworthy #-}
33

4+
{-# OPTIONS_GHC -Wno-unrecognised-warning-flags #-}
5+
{-# OPTIONS_GHC -Wno-x-partial #-}
6+
47
-- |
58
-- Module: Data.Text.Lazy.Builder.RealFloat
69
-- Copyright: (c) The University of Glasgow 1994-2002

tests/Tests/Properties/Substrings.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,8 @@ split p xs = loop xs
229229
(l, []) -> [l]
230230
(l, _ : s') -> l : loop s'
231231

232-
t_chunksOf_same_lengths k = conjoin . map ((===k) . T.length) . ini . T.chunksOf k
233-
where ini [] = []
234-
ini xs = init xs
232+
t_chunksOf_same_lengths k =
233+
conjoin . map ((===k) . T.length) . drop 1 . reverse . T.chunksOf k
235234

236235
t_chunksOf_length k t = len === T.length t .||. property (k <= 0 && len == 0)
237236
where len = L.sum . L.map T.length $ T.chunksOf k t

tests/Tests/Properties/Transcoding.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
-- | Tests for encoding and decoding
22

33
{-# LANGUAGE CPP, OverloadedStrings, ScopedTypeVariables #-}
4-
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
4+
{-# OPTIONS_GHC -Wno-missing-signatures #-}
5+
{-# OPTIONS_GHC -Wno-unrecognised-warning-flags #-}
6+
{-# OPTIONS_GHC -Wno-x-partial #-}
7+
58
module Tests.Properties.Transcoding
69
( testTranscoding
710
) where

0 commit comments

Comments
 (0)