@@ -1,9 +1,9 @@
11module Data.Index
22 ( ZeroBased
33 , first
4− , second
5− , third
4+ , unsafe
65 , next
6+ , toZeroBased
77 , toOneBased
88 , indexedMap
99 , indexedTraverse
@@ -32,14 +32,12 @@ first =
3232 ZeroBased 0
3333
3434
35−second :: ZeroBased
36−second =
37− ZeroBased 1
38−
39−
40−third :: ZeroBased
41−third =
42− ZeroBased 2
35+unsafe :: Int -> ZeroBased
36+unsafe n =
37+ if n < 0 then
38+ ZeroBased n
39+ else
40+ error "Compiler error, unacceptable call of Index.unsafe"
4341
4442
4543{-# INLINE next #-}
@@ -49,7 +47,12 @@ next (ZeroBased i) =
4947
5048
5149
52−-- ONE BASED
50+-- DESTRUCT
51+
52+
53+toZeroBased :: ZeroBased -> Int
54+toZeroBased (ZeroBased index) =
55+ index
5356
5457
5558toOneBased :: ZeroBased -> Int
@@ -124,3 +127,4 @@ indexedZipWithA func listX listY =
124127instance Binary ZeroBased where
125128 get = liftM ZeroBased get
126129 put (ZeroBased n) = put n
130+