on master help sign in
Change the Index API around for latest usage
ee5f359Evan Czaplicki
src/Data/Index.hs+15−11
@@ -1,9 +1,9 @@
1module Data.Index
1module Data.Index
2 ( ZeroBased
2 ( ZeroBased
3 , first
3 , first
4− , second
4+ , unsafe
5− , third
6 , next
5 , next
6+ , toZeroBased
7 , toOneBased
7 , toOneBased
8 , indexedMap
8 , indexedMap
9 , indexedTraverse
9 , indexedTraverse
@@ -32,14 +32,12 @@ first =
32 ZeroBased 0
32 ZeroBased 0
33
33
34
34
35−second :: ZeroBased
35+unsafe :: Int -> ZeroBased
36−second =
36+unsafe n =
37− ZeroBased 1
37+ if n < 0 then
38−
38+ ZeroBased n
39−
39+ else
40−third :: ZeroBased
40+ error "Compiler error, unacceptable call of Index.unsafe"
41−third =
42− ZeroBased 2
43
41
44
42
45{-# INLINE next #-}
43{-# INLINE next #-}
@@ -49,7 +47,12 @@ next (ZeroBased i) =
49
47
50
48
51
49
52−-- ONE BASED
50+-- DESTRUCT
51+
52+
53+toZeroBased :: ZeroBased -> Int
54+toZeroBased (ZeroBased index) =
55+ index
53
56
54
57
55toOneBased :: ZeroBased -> Int
58toOneBased :: ZeroBased -> Int
@@ -124,3 +127,4 @@ indexedZipWithA func listX listY =
124instance Binary ZeroBased where
127instance Binary ZeroBased where
125 get = liftM ZeroBased get
128 get = liftM ZeroBased get
126 put (ZeroBased n) = put n
129 put (ZeroBased n) = put n
130+