Skip to content

Instantly share code, notes, and snippets.

@eagletmt
Created January 4, 2010 00:40
Show Gist options
  • Save eagletmt/268210 to your computer and use it in GitHub Desktop.
Save eagletmt/268210 to your computer and use it in GitHub Desktop.
import Data.Array
import Data.Array.IArray (IArray)
import Data.Array.Unboxed (UArray)
import Data.Array.ST (STArray, thaw, freeze)
import Control.Monad.ST (ST, runST)
coerce :: (Ix i, IArray a e, IArray b e) => a i e -> b i e
coerce arr = runST $ thawST arr >>= freeze
where
thawST :: (Ix i, IArray a e) => a i e -> ST s (STArray s i e)
thawST = thaw
main = print $ (coerce $ listArray (0,3) [0..3] :: UArray Int Int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment