Figuring out the correct data container to use can be a bit tricky in Haskell, for my 2D grid application I thought using UArray
would be appropriate. However, as far as I can tell UArray
is not an instance of foldable
(not in Data.Array.IArray
nor Data.Array.Unboxed
).
Is there a reason for this? I can make my own helper functions but the absence of a foldable
instance suggests that maybe I shouldn't.
I believe such an instance is impossible, because it requires an extra constraint in the data type contained by the array, which cannot be expressed in Foldable. In mono-traversable, I do define MonoFoldable instances for unboxed and storable vectors.
EDIT: To be clear, the constraint I'm referring to is that all functions in Data.Vector.Unbox
only work if the value contained by the Vector
is an instance of Unbox
, whereas Foldable
requires that foldMap
, foldr
, etc, are defined for all possible types (as is the case for types like lists, boxed vectors, etc). There is no way with the Foldable
typeclass to state "the contained value must meet these constraints." With MonoFoldable
, there is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With