-- Array with access by a given index -- The type of arrays containing elements of type `a`: type Array a = (Int -> a) -- The empty array: emptyArray :: Array a emptyArray i = error "Undefined index position!" -- Put an element at an index into an array: putIndex :: Array a -> Int -> a -> Array a putIndex a i v = a' where a' j | i == j = v | otherwise = a j -- Get an element at an index position in an array: selector a[i] getIndex :: Array a -> Int -> a getIndex a i = a i ar12 :: Array Int ar12 = putIndex (putIndex emptyArray 1 42) 2 99 initArray :: a -> Array a --initArray v = const v initArray = const arHello :: Array String arHello = putIndex (putIndex (initArray "") 1 "Hello") 2 "world"