[Haskell-cafe] passing a polymorphic function as a parameter vs using it directly in a function definition

Pasqualino "Titto" Assini tittoassini at gmail.com
Fri Jul 16 16:10:34 EDT 2010


Thanks you all, now it makes sense.

      titto

On 15 July 2010 17:52, Brent Yorgey <byorgey at seas.upenn.edu> wrote:
> On Thu, Jul 15, 2010 at 01:20:11PM +0100, Pasqualino Titto Assini wrote:
>> Many thanks for the explanation.
>>
>> But I thought that GHC always derives the most generic type, why does
>> it fix my 'a' to 'Int' ?
>
> Note that this type
>
>  evalAST2 :: forall a. (Expr a -> IO()) -> AST -> IO ()
>
> means that the type a has to be chosen first, i.e. by the *caller* of
> evalAST2.  So evalAST2 is not free to use its argument k at whatever
> type it wants, it will be given a function of type (Expr T -> IO())
> for some type T that it didn't get to choose.  Forcing the caller to
> provide a polymorphic function, so that evalAST2 can choose at what
> type(s) to use it, is exactly what is expressed by the rank-2 type
>
>  evalAST2 :: (forall a. Expr a -> IO()) -> AST -> IO ()
>
> -Brent
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Pasqualino "Titto" Assini, Ph.D.
http://quicquid.org/


More information about the Haskell-Cafe mailing list