<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Why is it unfortunate? This looks like desired behavior to me. That is: I think these reference types should allow coercions between representationally equal types. Of course, that means that TestEquality is out.<div class=""><br class=""></div><div class="">Richard<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 2, 2018, at 5:04 PM, Edward Kmett <<a href="mailto:ekmett@gmail.com" class="">ekmett@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="gmail_quote"><div dir="ltr" class="">On Sun, Dec 2, 2018 at 7:55 PM David Feuer <<a href="mailto:david.feuer@gmail.com" class="">david.feuer@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="auto" class=""><div class="">Unfortunately, testEquality for STRef is not at all safe, for reasons we've previously discussed in another context.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class=""> <span class="Apple-converted-space"> </span>testEquality :: STRef s a -> STRef s b -> Maybe (a :~: b)</div><div dir="auto" class=""><font face="sans-serif" class=""><br class=""></font></div><div dir="auto" class=""><font face="sans-serif" class=""> <span class="Apple-converted-space"> </span>let x = [1, 2]</font></div><div dir="auto" class=""><font face="sans-serif" class=""> <span class="Apple-converted-space"> </span>foo :: STRef s [Int] <- newSTRef x</font></div><div dir="auto" class=""><font face="sans-serif" class=""> <span class="Apple-converted-space"> </span>let bar :: STRef s (ZipList Int) = coerce foo</font></div><div dir="auto" class=""><font face="sans-serif" class=""> <span class="Apple-converted-space"> </span>case testEquality foo bar of UH-OH</font></div><div dir="auto" class=""><font face="sans-serif" class=""><br class=""></font></div><div dir="auto" class=""><font face="sans-serif" class="">I suspect testCoercion actually will work here.</font></div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">You could patch up the problem by giving STRef (and perhaps MutVar#) a stricter role signature:</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">type role STRef nominal nominal</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">That might not break enough code to worry about; I'm not sure.</div></div></blockquote><div class=""><br class=""></div><div class="">That is rather unfortunate, as it means most if not all of these would be limited to TestCoercion.</div><div class=""><br class=""></div><div class="">-Edward </div><div class=""><br class=""></div><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="auto" class=""><div dir="auto" class=""><div class="gmail_quote" dir="auto"><div dir="ltr" class="">On Sun, Dec 2, 2018, 7:16 PM Edward Kmett <<a href="mailto:ekmett@gmail.com" target="_blank" class="">ekmett@gmail.com</a><span class="Apple-converted-space"> </span>wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class=""><div dir="ltr" class="">I'd like to propose adding a bunch of instances for TestEquality and TestCoercion to base and primitive types such as: IORef, STRef s, MVar as well as MutVar and any appropriately uncoercible array types we have in primitive.</div><div dir="ltr" class=""><br class=""></div><div dir="ltr" class=""><div dir="ltr" class="">With these you can learn about the equality of the types of elements of an STRef when you go to</div><div dir="ltr" class=""><br class=""></div><div dir="ltr" class=""> testEquality :: STRef s a -> STRef s b -> Maybe (a :~: b)<br class=""><div class=""><br class=""></div><div class="">I've been using an ad hoc versions of this on my own for some time, across a wide array of packages, based on Atze van der Ploeg's paper: <a href="https://dl.acm.org/citation.cfm?id=2976008" rel="noreferrer" target="_blank" class="">https://dl.acm.org/citation.cfm?id=2976008</a><span class="Apple-converted-space"> </span>and currently I get by by unsafeCoercing reallyUnsafePointerEquality# and unsafeCoercing the witness that I get back in turn. =/</div><div class=""><br class=""></div><div class="">With this the notion of a "Key" introduced there can be safely modeled with an STRef s (Proxy a).</div><div class=""><br class=""></div><div class="">This would make it {-# LANGUAGE Safe #-} for users to construct heterogeneous container types that don't need Typeable information about the values.</div></div></div><div dir="ltr" class=""><br class=""></div><div dir="ltr" class="">Implementation wise, these can either use the value equality of those underlying primitive types and then produce a witness either by unsafeCoerce, or by adding new stronger primitives in ghc-prim to produce the witness in a type-safe manner, giving us well typed core all the way down.</div><div dir="ltr" class=""><br class=""></div><div class="">-Edward</div><div dir="ltr" class=""><div class=""></div></div></div>_______________________________________________<br class="">Libraries mailing list<br class=""><a href="mailto:Libraries@haskell.org" rel="noreferrer" target="_blank" class="">Libraries@haskell.org</a><br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a></blockquote></div></div></div></blockquote></div></div></div></blockquote></div><br class=""></div></body></html>