Skip to content

Commit

Permalink
use new Data.Text.Builder.Linear.fromUnboundedDec
Browse files Browse the repository at this point in the history
  • Loading branch information
raehik committed Jul 14, 2024
1 parent fd4ee3b commit d38c99f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
type-level-show.flake = false;
singleraeh.url = "github:raehik/singleraeh";
singleraeh.flake = false;
linear-builder.url = "github:Bodigrim/linear-builder";
linear-builder.flake = false;
};
outputs = inputs:
let
Expand All @@ -39,20 +41,23 @@
packages.rerefined.source = inputs.rerefined;
packages.type-level-show.source = inputs.type-level-show;
packages.singleraeh.source = inputs.singleraeh;
packages.text-builder-linear.source = inputs.linear-builder;
devShell = nondevDevShell "ghc98";
};
haskellProjects.ghc96 = {
basePackages = pkgs.haskell.packages.ghc96;
packages.rerefined.source = inputs.rerefined;
packages.type-level-show.source = inputs.type-level-show;
packages.singleraeh.source = inputs.singleraeh;
packages.text-builder-linear.source = inputs.linear-builder;
devShell.mkShellArgs.name = "ghc96-strongweak";
};
haskellProjects.ghc94 = {
basePackages = pkgs.haskell.packages.ghc94;
packages.rerefined.source = inputs.rerefined;
packages.type-level-show.source = inputs.type-level-show;
packages.singleraeh.source = inputs.singleraeh;
packages.text-builder-linear.source = inputs.linear-builder;
devShell = nondevDevShell "ghc94";
};
};
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dependencies:

# strengthening
- text >= 2.0 && < 2.2
- text-builder-linear ^>= 0.1.2
- text-builder-linear ^>= 0.1.3

# instances
- rerefined ^>= 0.5.0
Expand Down
15 changes: 8 additions & 7 deletions src/Strongweak/Strengthen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,15 @@ instance Strengthen (NonEmpty a) where

-- | Strengthen a plain list into a sized vector by asserting length.
instance (VG.Vector v a, KnownNat n) => Strengthen (VGS.Vector v n a) where
-- TODO another case of TBL not supporting unbounded integrals
-- as of text-linear-builder-0.1.3, we can use 'fromUnboundedDec' for the
-- phantom vector size
-- I don't believe you can actually ever construct a vector with size
-- greater than @'maxBound' \@'Int'@. but still!
strengthen as =
case VGS.fromList as of
Just va -> Right va
Nothing -> failStrengthen1 $
[ "type: [a] -> Vector v "<>fromString (show n)<>" a"
[ "type: [a] -> Vector v "<>TBL.fromUnboundedDec n<>" a"
, "fail: wrong length (got "<>TBL.fromDec (length as)<>")" ]
where n = natVal'' @n

Expand Down Expand Up @@ -168,12 +171,10 @@ instance Strengthen Int64 where strengthen = strengthenBounded
--
-- @n@ must be "wider" than @m@.
--
-- @'FiniteBits' m@ and @'Show' n@ are for error printing. We're forced to
-- @'Show' n@ because linear-text-builder can't print unbounded integrals. PR:
-- https://github.com/Bodigrim/linear-builder/pull/20
-- @'FiniteBits' m@ is for error printing.
strengthenBounded
:: forall m n
. ( Typeable n, Integral n, Show n
. ( Typeable n, Integral n
, Typeable m, Integral m, Bounded m, FiniteBits m
) => n -> Either StrengthenFailure' m
strengthenBounded n
Expand All @@ -182,7 +183,7 @@ strengthenBounded n
[ "numeric strengthen: "<>fromString (show (typeRep' @n))
<>" -> "<>fromString (show (typeRep' @m))
, "bounds check does not hold: "
<>TBL.fromDec minBm<>" <= "<>fromString (show n)
<>TBL.fromDec minBm<>" <= "<>TBL.fromUnboundedDec n
<>" <= "<>TBL.fromDec maxBm
]
where
Expand Down
4 changes: 2 additions & 2 deletions strongweak.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ library
base >=4.18 && <5
, rerefined >=0.5.0 && <0.6
, text >=2.0 && <2.2
, text-builder-linear >=0.1.2 && <0.2
, text-builder-linear >=0.1.3 && <0.2
, vector >=0.12.3.1 && <0.14
, vector-sized >=1.5.0 && <1.7
default-language: GHC2021
Expand Down Expand Up @@ -94,7 +94,7 @@ test-suite spec
, rerefined >=0.5.0 && <0.6
, strongweak
, text >=2.0 && <2.2
, text-builder-linear >=0.1.2 && <0.2
, text-builder-linear >=0.1.3 && <0.2
, vector >=0.12.3.1 && <0.14
, vector-sized >=1.5.0 && <1.7
default-language: GHC2021

0 comments on commit d38c99f

Please sign in to comment.