module Array2D (

  Array2D, Update(..), empty, (#), (?),

  emptyWithValue

  ) where

import ArrayB

infix 0 ?
infixl 1 #
infix  2 :~, :=

type Array2D a = ArrayB (ArrayB a)

data Update a = (Int,Int) :~ (a -> a) | (Int,Int) := a

empty :: Array2D a
empty = emptyArrayWithValue emptyArrayB

emptyWithValue :: a -> Array2D a
emptyWithValue = emptyArrayWithValue . emptyArrayWithValue

(#) :: Array2D a -> Update a -> Array2D a
a#(n,m):~f = update n (update m f) a
a#p:=x     = a#p:~const x

(?) :: Array2D a -> (Int,Int) -> a
a ? (n,m) = a!n!m

