Error when ($) is used, but no error without

Niklas Broberg niklas.broberg at gmail.com
Thu Apr 27 02:31:12 EDT 2006


On 4/27/06, Robin Bate Boerop <robin_bb at acm.org> wrote:
> But, this code:
>
> class CC a
> type C x = CC a => a x
> f, g :: C a -> Int
> f _ = 3
> g x = f $ x  -- the only change

The problem is exactly the use of $. $ is an operator, not a built-in
language construct, and it has type (a -> b) -> a -> b. No forall's in
there, so you cannot give it a function argument that is existentially
quantified. Lots of people have been bitten by this when using the
magic runST with type "forall a. (forall s. ST s a) -> a".
Use parentheses when you have existentially quantified values and
everything should be just fine. :-)

/Niklas


>
> gives this error:
>
>      Inferred type is less polymorphic than expected
>        Quantified type variable `a' escapes
>        Expected type: a a1 -> b
>        Inferred type: C a1 -> Int
>      In the first argument of `($)', namely `f'
>      In the definition of `g': g x = f $ x
>
> What's going on here?
>
> --
> Robin Bate Boerop
>
>
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>


More information about the Glasgow-haskell-users mailing list