Performance question
Hal Daume III
hdaume@ISI.EDU
Wed, 2 Oct 2002 07:58:43 -0700 (PDT)
If I'm understanding you correctly, you just want to be able to put F|Gs
into an unbooxed array. You don't need to do this conversion stuff...you
can just define new instances. Something like:
instance MArray IOUArray F IO where
newArray (l,h) f = newArray (l,h) (f==F) >>= castIOUArray
newArray_ (l,h) =
do (arr :: IOUArray ix Bool) <- newArray_ (l,h)
castIOUArray arr
unsafeRead arr i =
do arr' <- castIOUArray arr
b <- unsafeRead arr' i
return (if b then F else G)
unsafeWrite arr i f = castIOUArray arr >>= \arr' ->
unsafeWrite arr' i (f==F)
here we have represented Fs by their isomorphic type Bool, which already
has MArray instances.
HTH
- Hal
--
Hal Daume III
"Computer science is no more about computers | hdaume@isi.edu
than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
On 2 Oct 2002, Ketil Z. Malde wrote:
>
> At the moment, I have a user defined data type on which I have defined
> some operations, instantiated (not derived) Eq and so on. However,
> for efficiency I'm storing the actual data in UArrays of Word8.
>
> In order for everything to work, I need functions 'toW8' and 'fromW8'
> to map between the data type and its representation in the array.
>
> I gather it is impossible to hide the 'Eq' instance of Word8 and/or
> redefine it, but could this be circumvented by instead of
>
> data Foo = F | G
>
> instance Eq Foo where
> F == _ = True
> _ == _ = False
>
> defining something like
>
> newtype Foo = F Word8
> f, g, h :: Foo
> f = F 0
> g = F 1
>
> and using the same instance declaration? And will it still fit into a
> UArray?
>
> (It is of course possible that, while profiling indicates otherwise,
> the conversion functions have little impact in practice; i.e. the
> optimizer will do away with them.)
>
> -kzm
> --
> If I haven't seen further, it is by standing in the footprints of giants
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>