Problems with specialization
Marcin 'Qrczak' Kowalczyk
qrczak@knm.org.pl
25 Mar 2001 17:24:33 GMT
There is something like this:
class MArray a e m
instance MArray IOArray e IO -- Instance with polymorphic elements
instance MArray IOUArray Char IO -- Instances with concrete elements
instance MArray IOUArray Int IO -- ...
instance MArray IOUArray Word IO -- ...
foo :: (MArray a e IO, Ix ix) => a ix e -> ix -> IO e
-- Specializations for ix = Int:
{-# SPECIALIZE foo ::
IOArray Int e -> Int -> IO e,
IOUArray Int Char -> Int -> IO Char,
IOUArray Int Int -> Int -> IO Int,
IOUArray Int Word -> Int -> IO Char
#-}
GHC silently drops the first specialization. Documentation says that
there are no partial specializations: all constrained type variables
must be concretized.
This is a pity, because the IOArray variant will not use the element
type anyway.
Ok, I understand that you can't have everything. So I tried the
following workaround to remove the element type from the constraint:
foo' :: Ix ix => IOArray ix e -> ix -> IO e
foo' = foo
{-# SPECIALIZE foo' :: IOArray Int e -> Int -> IO e #-}
Unfortunately ghc ignores the SPECIALIZE pragma when the definition
is too simple! Actually foo above must be nontrivial too, otherwise
all specializations are ignored.
Copy & paste of the definition just to get specialization would
be silly.
Any ideas?
--
__("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTĘPCZA
QRCZAK