game/src/Tool/Array.hs

24 lines
438 B
Haskell

module Tool.Array (
Array
, (!)
, clear
, malloc
) where
import Data.Vector (Vector, (!?), (//))
import qualified Data.Vector as Vector (replicate)
type Array a = Vector (Maybe a)
(!) :: Array a -> Int -> Maybe a
t ! k =
case t !? k of
Nothing -> Nothing
Just a -> a
clear :: Array a -> Int -> Array a
clear t k = t // [(k, Nothing)]
malloc :: Int -> Array a
malloc size = Vector.replicate size Nothing