<div dir="auto">newtype WrappedEnum a = WrappedEnum a<div dir="auto"><br></div><div dir="auto">instance Enum a => Storable (WrappedEnum a) where</div><div dir="auto"> ...</div><div dir="auto"><br></div><div dir="auto">deriving via (WrappedEnum Ordering)</div><div dir="auto"> instance Storable Ordering</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 8, 2019, 11:34 AM Sven Panne <<a href="mailto:svenpanne@gmail.com">svenpanne@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 dir="ltr">Am Di., 8. Okt. 2019 um 16:57 Uhr schrieb Simon Jakobi via Libraries <<a href="mailto:libraries@haskell.org" target="_blank" rel="noreferrer">libraries@haskell.org</a>>:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">That seems like a good idea! [...]</div></blockquote><div><br></div><div>Looks OK, but let's use toEnum in peekElemOff:</div><div><br></div><div> instance Storable Ordering where<br> sizeOf _ = sizeOf (undefined :: CInt)<br> alignment _ = alignment (undefined :: CInt)<br> peekElemOff p i = toEnum . fromIntegral <$> peekElemOff (castPtr p :: Ptr CInt) i<br> pokeElemOff p i = pokeElemOff (castPtr p :: Ptr CInt) i . fromIntegral . fromEnum</div><div><br></div><div>This is more symmetrical with pokeElemOff and less obfuscated. Note that the instance works for every Enum, so if there are more cases like Ordering, it might be worth to abstract that out.<br></div></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>