I should point out that cleaner solution is possible is the Overloaded
resolutions rules are modified a bit.
Normally given the class.
class Listable c b where
toList :: c -> [b]
to list will never be able to be resolved unless the signature is given
when toList is called because there is no way to derive the type of b
from the function call. However when given an instance declaration of
instance Listable [a] a where
toList c = c
the compiler should be able to resolve toList [1,2,3] however it
currently doesn't.
So if the compiler is modified to work a little harder before reporting
an unresolved Overloaded resolution the solution could be written as:
import Array
class Listable c b where
toList :: c -> [b]
class Find c a b where
find :: a -> c -> Maybe b
instance Listable [a] a where
toList c = c
instance (Eq a, Listable [(a,b)] (a,b)) => Find [(a,b)] a b where
find a c = lookup a (toList c)
instance Ix ix => Listable (Array ix el) (ix,el) where
toList c = assocs c
instance Ix ix => Find (Array ix el) ix el where
find a c | inRange (bounds c) a = Just (c!a)
| otherwise = Nothing
With out any fancy tricks.
--
Kevin Atkinson
[EMAIL PROTECTED]
http://metalab.unc.edu/kevina/