[Yhc] YHC Core Semantics

Bernie Pope bjpop at csse.unimelb.edu.au
Mon Mar 12 07:18:45 EDT 2007


> so is v208 the 1 from the original Haskell?  If so why is
> it then explicitly mentioned (CoreIntger 1)?  This
> function originally took 1 argument it now takes 2.

Note that the type of the function is:

increase :: Num a => a -> a

The traditional approach to handling class constraints is to
turn them into extra parameters of the function. Sometimes
this is called the "dictionary passing transformation (or
translation)". 

So in core, the type would be:

increase :: NumDictionary a -> a -> a

where NumDictionary is a data value which contains the
implementations of the methods of the num class. 

It might look something like this:

   data NumDictionary a = 
      NumDict
      { numPlus :: a -> a -> a
      , numTimes :: a -> a -> a
      , numFromInteger :: Integer -> a
      ... and so on ...
      }

Overloaded functions like (+) become:

   (+) :: NumDictionary a -> (a -> a -> a)
   (+) dict = numPlus dict 

So, I would say that v208 corresponds to
x in the original code, and v207 corresponds to the Num
dictionary, which is passed in to handle the overloading.

Note that (+) and fromInteger are both applied to v207.
These applications simply select out the implementations of
(+) and fromInteger from the dictionary.

Hopefully my explanation is correct and helpful.

Cheers,
Bernie.


More information about the Yhc mailing list