
Hi, I'm after some help understanding either what I'm doing wrong, or why this error occurs. I have a data type:
data T a = forall b. (Show b) => T b a
and I want to use/extract 'b' from this.
extShow (T b _) = b
This gives the following compilation error: extest.hs:5:0: Inferred type is less polymorphic than expected Quantified type variable `b' escapes When checking an existential match that binds $dShow :: {Show b} b :: b The pattern(s) have type(s): T t The body has type: b In the definition of `extShow': extShow (T b _) = b I tried adding a type signature:
extShow' :: (Show b) => T a -> b extShow' (T b _) = b
Now I get a different error: extest.hs:8:19: Couldn't match expected type `b' (a rigid variable) against inferred type `b1' (a rigid variable) `b' is bound by the type signature for `extShow'' at extest.hs:7:18 `b1' is bound by the pattern for `T' at extest.hs:8:10-14 In the expression: b In the definition of `extShow'': extShow' (T b _) = b It seems (to newbie me ;) ) like it should be possible to extract the first part of T, and deduce that it is an instance of the class 'Show'. The following seems ok:
doShow (T b _) = putStrLn (show b)
Thanks, Levi