I have this type and these functions:
data Tag a where
Tag :: (Show a, Eq a, Ord a, Storable a, Binary a) => a -> BL.ByteString -> Tag a
getVal :: Tag a -> a
getVal (Tag v _) = v
isBigger :: Tag a -> Tag a -> Bool
a `isBigger` b = (getVal a) > (getVal b)
The code doesn't typecheck:
No instance for (Ord a)
arising from a use of `>'
In the expression: (getVal a) > (getVal b)
In an equation for `isBigger':
a isBigger b = (getVal a) > (getVal b)
But I can't understand why not. Tag a
has the context (Show a, Eq a, Ord a, Storable a, Binary a)
, and getVa
l ought to preserve this context. Am I doing it wrong, or is this a limitation of the GADTs extension?
This works:
isBigger :: Tag a -> Tag a -> Bool
(Tag a _) `isBigger` (Tag b _) = a > b
Edit: I changed the example to a minimal example
Edit: Ok, why doesn't this typecheck?
isBigger :: Tag a -> Tag a -> Bool
isBigger ta tb =
let (Tag a _) = ta
(Tag b _) = tb
in
a > b