<div dir="auto">We should probably use something similar, but I don't think a dependency on primitive is a good idea.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 3, 2020, 14:28 Carter Schonwald <<a href="mailto:carter.schonwald@gmail.com">carter.schonwald@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hey Zemyla!</div><div>one fuzzy question i have, and perhaps you have a perspective on this, would/could the PrimMonad machinery in primitive help simplify / clean up stuff here too?<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 24, 2020 at 9:46 AM Zemyla <<a href="mailto:zemyla@gmail.com" target="_blank" rel="noreferrer">zemyla@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">It's currently hard to describe that a type should be usable with UArray or IOUArray, and almost impossible to describe without QualifiedConstraints that it should be usable with STUArray. And it's actually impossible to use GeneralizedNewtypeDeriving to derive new instances of IArray or MArray. It also means that it's difficult to keep the three sets of instances in sync.<div dir="auto"><br></div><div dir="auto">Therefore, there should be (taking inspiration from primitive) a class that describes types which can be used in unboxed arrays. It'd be something along the lines of:</div><div dir="auto"><br></div><div dir="auto">class Unboxed e where</div><div dir="auto">  unsafeNewUArray :: Int# -> e -> State# s -> (# State# s, MutableByteArray# s #)</div><div dir="auto">  unsafeNewUArray_ :: Const (Int# -> State# s -> (# State# s, MutableByteArray# s #)) e</div><div dir="auto">  unsafeReadUArray :: MutableByteArray# s -> Int# -> State# s -> (# State# s, e #)</div><div dir="auto">  unsafeWriteUArray :: MutableByteArray# s -> Int# -> e -> State# s -> State# s</div><div dir="auto">  unsafeIndexUArray :: ByteArray# -> Int# -> e</div><div dir="auto"><br></div><div dir="auto">And then the instances for UArray, STUArray, and IOUArray would be:</div><div dir="auto"><br></div><div dir="auto">instance Unboxed e => IArray UArray e where ...</div><div dir="auto">instance Unboxed e => MArray IOUArray e IO where ...</div><div dir="auto">instance Unboxed e => MArray (STUArray s) e (ST s) where ...</div><div dir="auto"><br></div><div dir="auto">Incidentally, this also means it'd be less effort to add instances like Unboxed CInt, Unboxed a => Unboxed (Complex a), and Unboxed Ordering.</div></div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>
</blockquote></div>