I want to implement an algorithm using the ST
monad and STUArray
s, and I want it to be able to work with both Float
and Double>
So here's the workaround I'm going with for now - creating a new typeclass for types for which (forall s. MArray (STUArray s) a (ST s))
:
class IArray UArray a => Unboxed a where
newSTUArray :: Ix i => (i, i) -> a -> ST s (STUArray s i a)
readSTUArray :: Ix i => STUArray s i a -> i -> ST s a
writeSTUArray :: Ix i => STUArray s i a -> i -> a -> ST s ()
instance Unboxed Float where
newSTUArray = newArray
readSTUArray = readArray
writeSTUArray = writeArray
instance Unboxed Double where
newSTUArray = newArray
readSTUArray = readArray
writeSTUArray = writeArray
While I'm not perfectly satisfied with this, I prefer it on rules because: