-- Generic utility functions module Util where import Data.Array {-# SPECIALIZE lookupA :: Array (Int, Int) e -> e -> (Int, Int) -> e #-} -- Index an array, but use a default value if the index is out of bounds. lookupA :: (Ix i) => Array i e -> e -> i -> e lookupA a def i = if inRange (bounds a) i then a ! i else def