
Hi, I'm still working with YHC Core to try to eventually to convert to Java. I'm having a little bit of trouble trying to fully understand the semantics of the YHC Core language. I've translated increase x = x+1 into Core for a simple example. The Core produced is Core { coreName :: Increase coreImports :: [Data.Ratio,Prelude] coreDatas :: [ [] coreFuncs :: [ CoreFunc { coreFuncName :: Increase.increase coreFuncArgs :: [v207,v208] coreFuncBody :: CorePos 4:1-4:16 (CoreApp ( CoreApp ( CoreFun Prelude.+ ) [CoreVar v207] ) [CoreVar v208,CoreApp ( CoreApp ( CoreFun Prelude.fromInteger ) [CoreVar v207] ) [CoreInteger 1]]) } ] } The bit I'm having trouble with is the CoreApp's they have an expression and a list of expressions, does this mean that the first expression should be applied to each element of the list? In particular from above (CoreApp (CoreApp (CoreFun Prelude.+) [CoreVar v207]) [ CoreVar v208, CoreApp (CoreApp (CoreFun Prelude.fromInteger) [CoreVar v207]) [CoreInteger 1] ] ) 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. As you can tell I'm a little confused! If anyone can enlighten me It'd be appreciated. Many Thanks, Ricky Barefield

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
participants (2)
-
Neil Mitchell
-
Ricky Barefield