Hi Iavor,<div><br></div><div>Thank you for your response.<br><div><br>On Wed, Jan 25, 2012 at 17:50, Iavor Diatchki wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Wed, Jan 25, 2012 at 7:21 AM, Thijs Alkemade wrote:<br>
> Also, we have a confusing problem when type checking a module. Above,<br>
> we showed the result of ":t map __ __" in ghci. However, if we put "f<br>
> = map __ __" in a module, we get:<br>
><br>
> tcRnModule: [(f.hs:1:9-10, GHC.Prim.Any * -> b),<br>
> (f.hs:1:12-13, [GHC.Prim.Any *])]<br>
><br>
> If I read GHC.Prim.Any * as forall a. a, then this is not correct: the<br>
> GHC.Prim.Any * in both holes should have the same type. We assume it<br>
> shows up because the type that should be there does not occur in the<br>
> type signature of f (as it's just [b]), but so far we've been unable<br>
> to figure out why this behavior is different in interactive mode. Does<br>
> someone have an idea about what to do to avoid the introduction of<br>
> these GHC.Prim.Any * types?<br>
<br>
</div>The type `Any` is just an ordinary monomorphic type, (e.g., like<br>
Int`). It is used to stand in for types that "do not matter" and may<br>
be thought of a special case of defaulting (i.e. resolving type<br>
ambiguity be selecting concrete types). How it is used is probably<br>
best illustrated with an example (you've found one, but I'll use a<br>
slightly simpler one). Consider the expression `null []`. It clearly<br>
has the type Bool, because `null` takes a list and returns a Bool, and<br>
`[]` is a list. However, there is nothing that forces the list<br>
elements to be of one type or another, so we cannot infer the full<br>
type of `[]`---in some sense, the expression `null []` is of type<br>
`forall a. Bool` where `a` is the type of the list elements.<br>
Inferring this type would not be useful because we have no way to<br>
specify what the `a` should be, and furthermore, it does not matter!<br>
So, whenever GHC infers a type `forall a. P => t` where `a` does not<br>
appear in `P` or `t`, it knows that the `a` does not matter, so t<br>
simply defaults it to `Any`.<br></blockquote><div><br></div><div>I believe the problem here is that GHC is inferring that a type does not matter (and thus defaults) when, actually, we want it to matter.</div><div><br></div>
<div>So, imagine this...</div><div><br></div><div><div>Prelude> :t map (__ :: forall a . a) (__ :: forall b . b)</div></div><div><br></div><div>... and trying to find out the types to which 'a' and 'b' are instantiated. I don't think the types should be Any thanks to the constraints imposed by 'map'.</div>
<div><br></div><div>Regards,<br>Sean</div></div></div></div>