Add instance Storable Ordering
David Feuer
david.feuer at gmail.com
Tue Oct 8 15:42:38 UTC 2019
But shouldn't Ordering have the alignment and size of Int8 rather than that
of Int? At least in principle?
On Tue, Oct 8, 2019, 11:38 AM David Feuer <david.feuer at gmail.com> wrote:
> newtype WrappedEnum a = WrappedEnum a
>
> instance Enum a => Storable (WrappedEnum a) where
> ...
>
> deriving via (WrappedEnum Ordering)
> instance Storable Ordering
>
> On Tue, Oct 8, 2019, 11:34 AM Sven Panne <svenpanne at gmail.com> wrote:
>
>> Am Di., 8. Okt. 2019 um 16:57 Uhr schrieb Simon Jakobi via Libraries <
>> libraries at haskell.org>:
>>
>>> That seems like a good idea! [...]
>>>
>>
>> Looks OK, but let's use toEnum in peekElemOff:
>>
>> instance Storable Ordering where
>> sizeOf _ = sizeOf (undefined :: CInt)
>> alignment _ = alignment (undefined :: CInt)
>> peekElemOff p i = toEnum . fromIntegral <$> peekElemOff (castPtr p ::
>> Ptr CInt) i
>> pokeElemOff p i = pokeElemOff (castPtr p :: Ptr CInt) i .
>> fromIntegral . fromEnum
>>
>> 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.
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20191008/55e4fb0d/attachment.html>
More information about the Libraries
mailing list