Skip to content

How to create UArray without writing each element twice?

{-# OPTIONS_GHC -O2 -ddump-simpl -dsuppress-all -dno-suppress-type-signatures #-}

module Lib where

import Data.Array.Unboxed

foo :: UArray Word Int
foo = listArray (0, 99) [0..99]

Looking at Core output, every element of the array is written twice. First, we populate entire array with 0s, then with actual values. This feels suboptimal, but I cannot figure out a better way to write such code. Admittedly, I don't know the API well, so I might be missing something obvious?..

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information