{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -Wno-dodgy-exports #-}
module Agda.Utils.IArray (module Agda.Utils.IArray, module Data.Array.IArray) where
import Data.Array.IArray
import Data.Array.Base ( IArray(..) )
import Data.Ix ( inRange )
#if MIN_VERSION_base(4,14,0)
import GHC.Ix ( unsafeIndex )
#endif
#if !MIN_VERSION_array(0,5,6)
{-# INLINE (!?) #-}
(!?) :: (IArray a e, Ix i) => a i e -> i -> Maybe e
!? :: forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> i -> Maybe e
(!?) a i e
arr i
i
| (i, i) -> i -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange (i, i)
b i
i = e -> Maybe e
forall a. a -> Maybe a
Just (e -> Maybe e) -> e -> Maybe e
forall a b. (a -> b) -> a -> b
$ a i e -> Int -> e
forall i. Ix i => a i e -> Int -> e
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> Int -> e
unsafeAt a i e
arr (Int -> e) -> Int -> e
forall a b. (a -> b) -> a -> b
$
#if MIN_VERSION_base(4,14,0)
(i, i) -> i -> Int
forall a. Ix a => (a, a) -> a -> Int
unsafeIndex (i, i)
b i
i
#else
index b i
#endif
| Bool
otherwise = Maybe e
forall a. Maybe a
Nothing
where b :: (i, i)
b = a i e -> (i, i)
forall i. Ix i => a i e -> (i, i)
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> (i, i)
bounds a i e
arr
#endif