pos 0.1.0.0 → 0.2.0.0
raw patch · 3 files changed
+17/−15 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Pos: class NSC ns
- Data.Pos: instance (Data.Pos.PosT n, Data.Pos.NSC (n1 'GHC.Base.:| ns)) => Data.Pos.NSC (n 'GHC.Base.:| (n1 : ns))
- Data.Pos: instance Data.Pos.PosT n => Data.Pos.NSC (n 'GHC.Base.:| '[])
+ Data.Pos: class NS ns
+ Data.Pos: instance (Data.Pos.PosT n, Data.Pos.NS (n1 : ns)) => Data.Pos.NS (n : n1 : ns)
+ Data.Pos: instance (TypeError ...) => Data.Pos.NS '[]
+ Data.Pos: instance Data.Pos.PosT n => Data.Pos.NS '[n]
- Data.Pos: fromNSP :: NSC ns => NonEmpty Pos
+ Data.Pos: fromNSP :: NS ns => NonEmpty Pos
- Data.Pos: fromNSTotalP :: NSC ns => Pos
+ Data.Pos: fromNSTotalP :: NS ns => Pos
- Data.Pos: nsLengthP :: NSC ns => Pos
+ Data.Pos: nsLengthP :: NS ns => Pos
Files
- pos.cabal +1/−1
- src/Data/Pos.hs +12/−9
- test/Main.hs +4/−5
pos.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: pos-version: 0.1.0.0+version: 0.2.0.0 synopsis: positive numbers description: A library for representing positive integers. . Useful for handling nonempty containers and fixed containers. category: Data, Numeric
src/Data/Pos.hs view
@@ -2,8 +2,8 @@ {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DerivingStrategies #-}-{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -74,7 +74,7 @@ type PosT, fromN, fromNP,- NSC (..),+ NS (..), -- ** miscellaneous @@ -277,20 +277,23 @@ FailUnless 'False err = GL.TypeError ( 'GL.Text "FailUnless: " 'GL.:<>: err) FailUnless 'True _ = () --- | conversion from nonempty list of Nats to Positives-type NSC :: NonEmpty Nat -> Constraint-class NSC ns where+-- | conversion from list of Nats to Positives+type NS :: [Nat] -> Constraint+class NS ns where fromNSP :: NonEmpty Pos fromNSTotalP :: Pos fromNSTotalP = productP (fromNSP @ns) nsLengthP :: Pos -instance PosT n => NSC (n ':| '[]) where+instance GL.TypeError ( 'GL.Text "NS: empty dimensions are not supported") => NS '[] where+ fromNSP = error "fromNSP: should not be here"+ nsLengthP = error "fromNSP: should not be here"+instance PosT n => NS '[n] where fromNSP = fromNP @n :| [] nsLengthP = _1P-instance (PosT n, NSC (n1 ':| ns)) => NSC (n ':| n1 ': ns) where- fromNSP = fromNP @n N.<| fromNSP @(n1 ':| ns)- nsLengthP = succP (nsLengthP @(n1 ':| ns))+instance (PosT n, NS (n1 ': ns)) => NS (n ': n1 ': ns) where+ fromNSP = fromNP @n N.<| fromNSP @(n1 ': ns)+ nsLengthP = succP (nsLengthP @(n1 ': ns)) -- | construct a valid 'Pos' using a 'Nat' _P :: forall n. PosT n => Pos
test/Main.hs view
@@ -3,7 +3,6 @@ {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-}-{-# LANGUAGE TypeOperators #-} module Main where @@ -43,8 +42,8 @@ , testCase "reads space between" $ reads @Pos " 9 P" @?= [] , testCase "reads leading spaces and extra" $ reads @Pos " 9P xyz" @?= [(_9P, " xyz")] , testCase "reads leading spaces and extra" $ reads @Pos " 123P" @?= [(_P @123, "")]- , testCase "fromNSP" $ fromNSP @(4 ':| '[]) @?= (_4P :| [])- , testCase "fromNSP" $ fromNSP @(4 ':| '[6, 3]) @?= (_4P :| [_6P, _3P])+ , testCase "fromNSP" $ fromNSP @'[4] @?= (_4P :| [])+ , testCase "fromNSP" $ fromNSP @'[4, 6, 3] @?= (_4P :| [_6P, _3P]) , testCase "fromNP 1" $ fromNP @1 @?= _1P , testCase "fromNP 2" $ fromNP @2 @?= _2P , testCase "fromNP 3" $ fromNP @3 @?= _3P@@ -68,10 +67,10 @@ , testCase "fromN 4" $ fromN @4 @?= 4 , testCase "fromN 1" $ fromN @1 @?= 1 , testCase "fromNSTotalP" $- fromNSTotalP @(2 ':| '[3, 20])+ fromNSTotalP @'[2, 3, 20] @?= _P @120 , testCase "fromNSP" $- fromNSP @(2 ':| '[3, 20])+ fromNSP @'[2, 3, 20] @?= _2P :| [_3P, _20P] , testCase "pPosInt" $ P.readP_to_S pPosInt " 12xyz"