Mutable arrays in Haskell 98

Mark Tullsen mtullsen@cse.ogi.edu
Wed, 27 Mar 2002 15:41:52 -0800


Josť Romildo Malaquias wrote:
> ...
> My attempt was
> 
>   mapIOArray :: Ix ix => (a -> b) -> IOArray ix a -> IO (IOArray ix b)
>   mapIOArray f v = do w <- newIOArray bounds ????????????
>                       mapping w (range bounds)
>       where
>       bounds = boundsIOArray v
>       mapping w (i:is) = do x <- readIOArray v i
>                             writeIOArray w i (f x)
>                             mapping w is
>       mapping w []     = return w
> 
> But I do not know what to use to replace the ????????????. Is there
> a polymorphic value in Haskell that can be of any type?
> 

Yes, use "undefined" from the Prelude:

  undefined        :: a
  undefined | False = undefined

- Mark