You have to worry about json having a floating point number or an integer that is too large to be represented in a Word32, although you could also just let it overflow if you don't care too much. There's probably an easier way to do this, but this is what I came up with.instance FromJSON CUid whereparseJSON (Number n) = docase floatingOrInteger n ofRight i | inrange i -> return . CUid . fromIntegral $ i-- not an integer, or not in range_ -> memptywhereinrange :: Integer -> Boolinrange i = fromIntegral i >= (minBound @Word32) &&fromIntegral i <= (maxBound @Word32)-- not a numberparseJSON _ = memptyOn Thu, Aug 9, 2018 at 11:37 AM, PICCA Frederic-Emmanuel <frederic-emmanuel.picca@synchrotron-soleil.fr > wrote:Hello, I try to write the instance for the CUid[1] type
But I do not know what to do.
instance FromJSON CUid where
parseJSON = ...
{-# INLINE parseJSON #-}
Thansk for your help
[1] https://hackage.haskell.org/package/base-4.11.1.0/docs/Syste m-Posix-Types.html#t:CUid
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners