[Haskell-cafe] Data.Foldable UArray

Marcus D. Gabriel marcus at gabriel.name
Thu Feb 20 21:12:54 UTC 2014


Hello,

I wanted to make a simple Data.Foldable UArray, and I naively modelled
it on

> instance Ix i => Foldable (Array i) where
>  foldr f z = Prelude.foldr f z . elems

with, of course,

> instance Ix i => Foldable (UArray i) where
> foldr f z = Prelude.foldr f z . elems

which did not work yielding the following type message

  Could not deduce (IArray UArray a) arising from a use of `elems'
  from the context (Ix i) bound by the instance declaration at
  ... Possible fix: add an instance declaration for (IArray UArray
  a) In the second argument of `(.)', namely `elems' In the
  expression: Data.List.foldr f z . elems In an equation for
  `foldr': foldr f z = Data.List.foldr f z . elems

I clearly do not understand something because I cannot make this work,
and I am not sure why.

With the Haskell type system or even with ghc extensions, can one even
make a Data.Foldable UArray?  If so, how?

Thanks in advance,
- Marcus


More information about the Haskell-Cafe mailing list