<div dir="ltr"><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Feb 20, 2014 at 11:12 PM, Marcus D. Gabriel <span dir="ltr"><<a href="mailto:marcus@gabriel.name" target="_blank">marcus@gabriel.name</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hello,<br>
<br>
I wanted to make a simple Data.Foldable UArray, and I naively modelled<br>
it on<br>
<br>
> instance Ix i => Foldable (Array i) where<br>
>  foldr f z = Prelude.foldr f z . elems<br>
<br>
with, of course,<br>
<br>
> instance Ix i => Foldable (UArray i) where<br>
> foldr f z = Prelude.foldr f z . elems<br>
<br>
which did not work yielding the following type message<br>
<br>
  Could not deduce (IArray UArray a) arising from a use of `elems'<br>
  from the context (Ix i) bound by the instance declaration at<br>
  ... Possible fix: add an instance declaration for (IArray UArray<br>
  a) In the second argument of `(.)', namely `elems' In the<br>
  expression: Data.List.foldr f z . elems In an equation for<br>
  `foldr': foldr f z = Data.List.foldr f z . elems<br>
<br>
I clearly do not understand something because I cannot make this work,<br>
and I am not sure why.<br>
<br>
With the Haskell type system or even with ghc extensions, can one even<br>
make a Data.Foldable UArray?  If so, how?<br>
<br>
Thanks in advance,<br>
- Marcus<br></blockquote><div><br></div><div>You could create an instance of MonoFoldable for UArray, similar to how the instance for unboxed vectors works[1]. There's no inherent reason why the Array instances don't exist there yet, I simply didn't get around to adding them yet.</div>

<div><br></div><div>[1] <a href="https://github.com/snoyberg/mono-traversable/blob/d81bf2fe5ef4ee5957f3a5c54af07a00637c932f/src/Data/MonoTraversable.hs#L502">https://github.com/snoyberg/mono-traversable/blob/d81bf2fe5ef4ee5957f3a5c54af07a00637c932f/src/Data/MonoTraversable.hs#L502</a> </div>

</div></div></div>