Skip to content

Commit c50f99d

Browse files
committed
General maintenance
1 parent 1631576 commit c50f99d

File tree

5 files changed

+40
-54
lines changed

5 files changed

+40
-54
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ jobs:
5454
- uses: actions/checkout@v2
5555
with:
5656
submodules: 'recursive'
57-
- uses: cachix/install-nix-action@v8
57+
- uses: cachix/install-nix-action@v12
58+
with:
59+
nix_path: nixpkgs=channel:nixos-unstable
5860
- run: nix-build
5961

6062
stack:

default.nix

+16-29
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,21 @@
1-
{ pkgs ? import <nixpkgs> { }, compiler ? null, hoogle ? true
2-
, forShell ? pkgs.lib.inNixShell }:
1+
{ nixpkgsSrc ? builtins.fetchTarball {
2+
url =
3+
"https://github.com/NixOS/nixpkgs/archive/540dccb2aeaffa9dc69bfdc41c55abd7ccc6baa3.tar.gz"; # nixos-unstable
4+
sha256 = "1j58m811w7xxjncf36hqcjqsfj979hkfcwx9wcrm3g3zbayavapg";
5+
}, pkgs ? import nixpkgsSrc { }, compiler ? null, extraOverrides ? _: _: { }
6+
, modifier ? x: x }:
37

48
let
5-
src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
6-
7-
compiler' = if compiler != null then
8-
compiler
9+
haskellPackages = if compiler == null then
10+
pkgs.haskellPackages
911
else
10-
"ghc" + pkgs.lib.concatStrings
11-
(pkgs.lib.splitVersion pkgs.haskellPackages.ghc.version);
12-
13-
# Any overrides we require to the specified haskell package set
14-
haskellPackages = with pkgs.haskell.lib;
15-
pkgs.haskell.packages.${compiler'}.override {
16-
overrides = self: super:
17-
{ } // pkgs.lib.optionalAttrs hoogle {
18-
ghc = super.ghc // { withPackages = super.ghc.withHoogle; };
19-
ghcWithPackages = self.ghc.withPackages;
20-
};
21-
};
12+
pkgs.haskell.packages.${compiler};
2213

23-
# Generate a haskell derivation using the cabal2nix tool on `package.yaml`
24-
drv = let old = haskellPackages.callCabal2nix "" src { };
25-
in old // {
26-
env = pkgs.lib.overrideDerivation old.env (attrs:
27-
pkgs.lib.optionalAttrs hoogle {
28-
shellHook = attrs.shellHook + ''
29-
export HIE_HOOGLE_DATABASE="$(cat $(${pkgs.which}/bin/which hoogle) | sed -n -e 's|.*--database \(.*\.hoo\).*|\1|p')"
30-
'';
31-
});
32-
};
14+
in haskellPackages.developPackage {
15+
name = "";
16+
root = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
17+
overrides = with pkgs.haskell.lib;
18+
pkgs.lib.composeExtensions (_self: _super: { }) extraOverrides;
19+
inherit modifier;
20+
}
3321

34-
in if forShell then drv.env else drv

package.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ tests:
6161
- checkers >=0.5.6
6262
- exact-real
6363
when:
64-
condition: impl(ghc < 8.0.0)
65-
buildable: false
64+
condition: impl(ghc < 8.0.0)
65+
buildable: false
6666

6767
doctests:
6868
main: Doctests.hs

release.nix

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
{ pkgs ? import <nixpkgs> { }, compiler ? "ghc884" }:
1+
{ pkgs ? import <nixpkgs> { }, compiler ? null }:
22

33
with pkgs.haskell.lib;
44

55
let
6-
drv = import ./default.nix {
7-
inherit pkgs compiler;
8-
hoogle = false;
9-
forShell = false;
10-
};
6+
drv = import ./default.nix { inherit pkgs compiler; };
117

128
docDrv = drv:
139
(overrideCabal drv (drv: {

src/Data/CReal/Internal.hs

+17-16
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import GHC.Real (Ratio(..), (%))
7575
import GHC.TypeLits
7676
import Text.Read
7777
import qualified Text.Read.Lex as L
78-
import System.Random (Random(..), RandomGen(..))
78+
import System.Random (Random(..))
7979
import Control.Concurrent.MVar
8080
import Control.Exception
8181
import System.IO.Unsafe (unsafePerformIO)
@@ -128,7 +128,7 @@ atPrecision :: CReal n -> Int -> Integer
128128
(CR mvc f) `atPrecision` (!p) = unsafePerformIO $ modifyMVar mvc $ \vc -> do
129129
vc' <- evaluate vc
130130
case vc' of
131-
Current j v | j >= p -> do
131+
Current j v | j >= p ->
132132
pure (vc', v /^ (j - p))
133133
_ -> do
134134
v <- evaluate $ f p
@@ -268,8 +268,8 @@ instance Floating (CReal n) where
268268
-- 0.75 <= x <= 2
269269
| l == 0 -> logBounded x
270270
-- x >= 2
271-
| l > 0 -> let a = x `shiftR` l
272-
in logBounded a + fromIntegral l *. ln2
271+
| otherwise -> let a = x `shiftR` l
272+
in logBounded a + fromIntegral l *. ln2
273273

274274
sqrt x = crMemoize (\p -> let n = atPrecision x (2 * p)
275275
in isqrt n)
@@ -297,7 +297,7 @@ instance Floating (CReal n) where
297297

298298
tan x = sin x .* recip (cos x)
299299

300-
asin x = (atan (x .*. recipBounded (1 + sqrt (1 - squareBounded x)))) `shiftL` 1
300+
asin x = atan (x .*. recipBounded (1 + sqrt (1 - squareBounded x))) `shiftL` 1
301301

302302
acos x = piBy2 - asin x
303303

@@ -355,9 +355,7 @@ instance KnownNat n => RealFrac (CReal n) where
355355
v = x `atPrecision` p
356356
r = v .&. (bit p - 1)
357357
n = unsafeShiftR (v - r) p
358-
in case r /= 0 of
359-
True -> fromInteger $ n + 1
360-
_ -> fromInteger n
358+
in if r /= 0 then fromInteger $ n + 1 else fromInteger n
361359

362360
floor x = let p = crealPrecision x
363361
v = x `atPrecision` p
@@ -411,7 +409,7 @@ instance KnownNat n => Eq (CReal n) where
411409
x == y = let p = crealPrecision x + 2
412410
in (atPrecision x p - atPrecision y p) /^ 2 == 0
413411

414-
-- | Like equality values of type @CReal p@ are compared at precision @p@.
412+
-- | Like equality, values of type @CReal p@ are compared at precision @p@.
415413
instance KnownNat n => Ord (CReal n) where
416414
compare (CR mvx _) (CR mvy _) | mvx == mvy = EQ
417415
compare x y = let p = crealPrecision x + 2
@@ -442,7 +440,7 @@ instance KnownNat n => Random (CReal n) where
442440
--
443441

444442
piBy4 :: CReal n
445-
piBy4 = (atanBounded (recipBounded 5) `shiftL` 2) - atanBounded (recipBounded 239) -- Machin Formula
443+
piBy4 = atanBounded (recipBounded 5) `shiftL` 2 - atanBounded (recipBounded 239) -- Machin Formula
446444

447445
piBy2 :: CReal n
448446
piBy2 = piBy4 `shiftL` 1
@@ -609,7 +607,7 @@ shiftR :: CReal n -> Int -> CReal n
609607
shiftR x n = crMemoize (\p -> let p' = p - n
610608
in if p' >= 0
611609
then atPrecision x p'
612-
else atPrecision x 0 /^ (negate p'))
610+
else atPrecision x 0 /^ negate p')
613611

614612
-- | @x \`shiftL\` n@ is equal to @x@ multiplied by 2^@n@
615613
--
@@ -645,8 +643,7 @@ rationalToDecimal places (n :% d) = p ++ is ++ if places > 0 then "." ++ fs else
645643
_ -> ""
646644
ds = show (roundD (abs n * 10^places) d)
647645
l = length ds
648-
(is, fs) = if | l <= places -> ("0", replicate (places - l) '0' ++ ds)
649-
| otherwise -> splitAt (l - places) ds
646+
(is, fs) = if l <= places then ("0", replicate (places - l) '0' ++ ds) else splitAt (l - places) ds
650647

651648

652649
--
@@ -713,7 +710,7 @@ isqrt :: Integer -> Integer
713710
isqrt x | x < 0 = error "Sqrt applied to negative Integer"
714711
| x == 0 = 0
715712
| otherwise = until satisfied improve initialGuess
716-
where improve r = unsafeShiftR (r + (x `div` r)) 1
713+
where improve r = unsafeShiftR (r + x `div` r) 1
717714
satisfied r = let r2 = r * r in r2 <= x && r2 + unsafeShiftL r 1 >= x
718715
initialGuess = bit (unsafeShiftR (log2 x) 1)
719716

@@ -727,7 +724,7 @@ findFirstMonotonic :: (Int -> Bool) -> Int
727724
findFirstMonotonic p = findBounds 0 1
728725
where findBounds !l !u = if p u then binarySearch l u
729726
else findBounds u (u * 2)
730-
binarySearch !l !u = let !m = l + ((u - l) `div` 2)
727+
binarySearch !l !u = let !m = l + (u - l) `div` 2
731728
in if | l+1 == u -> l
732729
| p m -> binarySearch l m
733730
| otherwise -> binarySearch m u
@@ -743,7 +740,11 @@ findFirstMonotonic p = findBounds 0 1
743740
-- [1,-2,3,-4,5]
744741
{-# INLINABLE alternateSign #-}
745742
alternateSign :: Num a => [a] -> [a]
746-
alternateSign = \ls -> foldr (\a r b -> if b then (negate a):r False else a:r True) (const []) ls False
743+
alternateSign ls = foldr
744+
(\a r b -> if b then negate a : r False else a : r True)
745+
(const [])
746+
ls
747+
False
747748

748749
-- | @powerSeries q f x `atPrecision` p@ will evaluate the power series with
749750
-- coefficients @q@ up to the coefficient at index @f p@ at value @x@

0 commit comments

Comments
 (0)