[Yhc] Re: YHC Core Semantics

Neil Mitchell ndmitchell at gmail.com
Mon Mar 12 07:24:32 EDT 2007


Hi Ricky,

> I'm still working with YHC Core to try to eventually to convert to Java.

Cool :)

> I'm having a little bit of trouble trying to fully understand the semantics
> of the YHC Core language.

> 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.

Dictionaries are tripping you up here. The type signature of increase is Num:

increase :: Num a => a -> a
increase x = x + fromInteger 1

Plus an explicit insertion of fromInteger, as required by the Haskell report.

This is then desugared by Yhc (and also in a same way by GHC and Hugs) to:

increase :: (a -> a -> a {- (+) -}, Integer -> a {- fromInteger -},
...) -> a -> a
increase num_dictionary x = ((+) num_dictionary) x ((fromInteger
num_dictionary) 1)

Where (+) and fromInteger just select an element out of the tuple and apply it.

v207 is the dictionary and v208 is the number in this case.

To answer your question, the semantics of CoreApp are to evaluate the
left thing to a function, then apply the right things as the
arguments, in order.

I suspect for the moment you'll want to do:

increase :: Int -> Int
increase x = x + 1

The explicit type signature removes the dictionaries and should leave
everything fine for you.

Thanks

Neil


More information about the Yhc mailing list