I try to define list of constrained polymorphic values, e.g.
myList = ["foo", 5] :: [Show a => a]
which yields the following error (GHCi, version 8.6.5)
GHC doesn't yet support impredicative polymorphism
Anyways, is it possible to specify a type such that, for example, functions of the form f :: Show a => [a] -> [String]
could consume a constrained value like above?
In other words, is there a way to verify the following code by the compiler?
(++ "fork") . show <$> ["foo", 5]
I currently try to test a Show
type class instance of a GADT by defining a dataset of values and expected results [(value, "expectedResult")]
. But, due to the fact that GADTs constructors specify the values type, it is not possible to do this naively.
show
forString -> String
is a different one then theshow
forInt -> String
. So what would the type forshow
be at the left side of<$>
? – Willem Van Onsemforall a. Show a => [a] -> [String]
, i hoped that maybe with RankNTypes there could be a possibility to make it possible – Nicolas Heimann[Wrapper]
which is a complicated type isomorphic to the simpler[String]
. This is a known anti-pattern. – chi