fixed-length 0.0.0.1 → 0.0.0.2
raw patch · 2 files changed
+39/−18 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- fixed-length.cabal +2/−2
- src/Data/FixedLength.hs +37/−16
fixed-length.cabal view
@@ -1,5 +1,5 @@ Name: fixed-length-Version: 0.0.0.1+Version: 0.0.0.2 License: BSD3 License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de>@@ -25,7 +25,7 @@ Build-Type: Simple Source-Repository this- Tag: 0.0.0.1+ Tag: 0.0.0.2 Type: darcs Location: http://code.haskell.org/~thielema/fixed-length/
src/Data/FixedLength.hs view
@@ -52,6 +52,20 @@ switch _ x = x +newtype+ SwitchPos f list =+ SwitchPos {runSwitchPos :: f list (Position list)}++switchPos ::+ (C list, Position list ~ pos) =>+ f Empty.T Zero ->+ (forall list0 pos0. (C list0, Position list0 ~ pos0) =>+ f (NonEmpty.T list0) (Succ pos0)) ->+ f list pos+switchPos empty nonEmpty =+ runSwitchPos $ switch (SwitchPos empty) (SwitchPos nonEmpty)++ end :: Empty.T a end = Empty.Cons @@ -121,12 +135,12 @@ instance Ord Zero where compare _ _ = EQ -newtype Update a list = Update {runUpdate :: Position list -> list a -> list a}+newtype Update a list pos = Update {runUpdate :: pos -> list a -> list a} updatePos :: C list => (a -> a) -> Position list -> list a -> list a updatePos f = runUpdate $- switch+ switchPos (Update $ \ _ Empty.Cons -> Empty.Cons) (Update $ \pos0 (NonEmpty.Cons x xs) -> case pos0 of@@ -137,12 +151,12 @@ update f (WrapPos k) = updatePos f k -newtype Index a list = Index {runIndex :: Position list -> list a -> a}+newtype Index a list pos = Index {runIndex :: pos -> list a -> a} indexPos :: C list => Position list -> list a -> a indexPos = runIndex $- switch+ switchPos (Index $ \ _ {- Zero -} Empty.Cons -> error "impossible index") (Index $ \pos0 (NonEmpty.Cons x xs) -> case pos0 of@@ -152,12 +166,12 @@ index :: C list => WrapPos list -> list a -> a index (WrapPos k) = indexPos k -newtype Indices list = Indices {runIndices :: list (Position list)}+newtype Indices list pos = Indices {runIndices :: list pos} indicesPos :: C list => list (Position list) indicesPos = runIndices $- switch+ switchPos (Indices $ Empty.Cons) (Indices $ NonEmpty.Cons Stop $ map Succ indicesPos) @@ -167,17 +181,24 @@ newtype WrapPos list = WrapPos {unwrapPos :: Position list} +swapWrapPosSucc :: WrapPos (NonEmpty.T list) -> Succ (WrapPos list)+swapWrapPosSucc (WrapPos n) =+ case n of+ Stop -> Stop+ Succ m -> Succ (WrapPos m)++ newtype NumFromPos list = NumFromPos {runNumFromPos :: WrapPos list -> Word} numFromPos :: C list => WrapPos list -> Word numFromPos = runNumFromPos $ switch- (NumFromPos $ \(WrapPos _) -> error "numFromPos")- (NumFromPos $ \(WrapPos n) ->- case n of+ (NumFromPos $ \_ -> error "numFromPos")+ (NumFromPos $ \n ->+ case swapWrapPosSucc n of Stop -> 0- Succ m -> 1 + numFromPos (WrapPos m))+ Succ m -> 1 + numFromPos m) newtype Compare a list = Compare {runCompare :: WrapPos list -> WrapPos list -> a}@@ -187,9 +208,9 @@ runCompare $ switch (Compare $ \_ _ -> error "equalPos")- (Compare $ \(WrapPos i) (WrapPos j) ->- case (i,j) of- (Succ k, Succ l) -> WrapPos k == WrapPos l+ (Compare $ \i j ->+ case (swapWrapPosSucc i, swapWrapPosSucc j) of+ (Succ k, Succ l) -> k == l (Stop, Stop) -> True _ -> False) @@ -198,9 +219,9 @@ runCompare $ switch (Compare $ \_ _ -> error "equalPos")- (Compare $ \(WrapPos i) (WrapPos j) ->- case (i,j) of- (Succ k, Succ l) -> compare (WrapPos k) (WrapPos l)+ (Compare $ \i j ->+ case (swapWrapPosSucc i, swapWrapPosSucc j) of+ (Succ k, Succ l) -> compare k l (Stop, Stop) -> EQ (Stop, Succ _) -> LT (Succ _, Stop) -> GT)