
On Thu, Jun 13, 2019 at 11:15:23AM +0530, Sandeep.C.R via Haskell-Cafe wrote:
This seems to work for me...
someCheck :: forall a. (Show a, Read a, Eq a) => String -> a -> Bool someCheck s v = (read . show . (read :: String -> a) $ s) == v
Probably requires 'ScopedTypeVariables'...
Yes. Another variant is: {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} someCheck :: (Show a, Read a, Eq a) => String -> a -> Bool someCheck s (v :: a) = (read . show $ read @a s) == v which amounts to the same thing, but is perhaps simpler. For fun, with GHC 8.6 and "BlockArguments" we can drop some parentheses: {-# LANGUAGE BlockArguments #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE ScopedTypeVariables #-} someCheck :: forall a. (Show a, Read a, Eq a) => String -> a -> Bool someCheck s v = v == do read $ show $ read @a s -- Viktor.