Skip to content
Snippets Groups Projects
Commit c75d2ee1 authored by Teo Camarasu's avatar Teo Camarasu
Browse files

add validity patch

parent f26f0fbe
No related branches found
No related tags found
1 merge request!171Add patches
diff --git a/src/Data/Validity.hs b/src/Data/Validity.hs
index cbebf1f..9b3fd1a 100644
--- a/src/Data/Validity.hs
+++ b/src/Data/Validity.hs
@@ -466,27 +466,39 @@ instance Validity Int where
-- | NOT trivially valid on GHC because small number types are represented using a 64bit structure underneath.
instance Validity Int8 where
+#if !MIN_VERSION_base(4,16,0)
validate (I8# i#) =
mconcat
[ declare "The contained integer is smaller than 2^7 = 128" $ isTrue# (i# <=# 127#),
declare "The contained integer is greater than or equal to -2^7 = -128" $ isTrue# (i# >=# -128#)
]
+#else
+ validate = trivialValidation
+#endif
-- | NOT trivially valid on GHC because small number types are represented using a 64bit structure underneath.
instance Validity Int16 where
+#if !MIN_VERSION_base(4,16,0)
validate (I16# i#) =
mconcat
[ declare "The contained integer is smaller than 2^15 = 32768" $ isTrue# (i# <=# 32767#),
declare "The contained integer is greater than or equal to -2^15 = -32768" $ isTrue# (i# >=# -32768#)
]
+#else
+ validate = trivialValidation
+#endif
-- | NOT trivially valid on GHC because small number types are represented using a 64bit structure underneath.
instance Validity Int32 where
+#if !MIN_VERSION_base(4,16,0)
validate (I32# i#) =
mconcat
[ declare "The contained integer is smaller than 2^31 = 2147483648" $ isTrue# (i# <=# 2147483647#),
declare "The contained integer is greater than or equal to -2^31 = -2147483648" $ isTrue# (i# >=# -2147483648#)
]
+#else
+ validate = trivialValidation
+#endif
-- | Trivially valid
instance Validity Int64 where
@@ -498,18 +510,30 @@ instance Validity Word where
-- | NOT trivially valid on GHC because small number types are represented using a 64bit structure underneath.
instance Validity Word8 where
+#if !MIN_VERSION_base(4,16,0)
validate (W8# w#) =
declare "The contained integer is smaller than 2^8 = 256" $ isTrue# (w# `leWord#` 255##)
+#else
+ validate = trivialValidation
+#endif
-- | NOT trivially valid on GHC because small number types are represented using a 64bit structure underneath.
instance Validity Word16 where
+#if !MIN_VERSION_base(4,16,0)
validate (W16# w#) =
declare "The contained integer is smaller than 2^16 = 65536" $ isTrue# (w# `leWord#` 65535##)
+#else
+ validate = trivialValidation
+#endif
-- | NOT trivially valid on GHC because small number types are represented using a 64bit structure underneath.
instance Validity Word32 where
+#if !MIN_VERSION_base(4,16,0)
validate (W32# w#) =
declare "The contained integer is smaller than 2^32 = 4294967296" $ isTrue# (w# `leWord#` 4294967295##)
+#else
+ validate = trivialValidation
+#endif
-- | Trivially valid
instance Validity Word64 where
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment