Performance: Faster to define a function writing out all arguments?

Alexander Fuchs alexander.fuchs at uni-koblenz.de
Mon May 12 11:52:04 EDT 2008


Hi Don.

Don Stewart wrote:
> alexander.fuchs:
>>
>> In a happy parser I have this code 1):
>>
>> %monad { Parsed } { thenP } { returnP }
>>
>> type Parsed = State Env.Env
>>
>> returnP :: a -> Parsed a
>> returnP a = return a
>>
>> thenP :: Parsed a -> (a -> Parsed b) -> Parsed b
>> thenP x k = x >>= k
>>
>>
>> An alternative was this 2) (yes, redundant in happy):
>>
>> returnP :: a -> Parsed a
>> returnP = return
>>
>> thenP :: Parsed a -> (a -> Parsed b) -> Parsed b
>> thenP = (>>=)
>>
> 
> Could you submit a minimal, complete grammar file, so
> we can look at the generated code?

After reducing and simplifying the grammar file to the minimum for my 
sample input I can't see any difference in performance anymore. Due to 
other code changes the difference is almost non-existent anymore even 
before simplification. I blame laziness for my lack of intuition of what 
is going on ;-)


Anyway, as I am still wondering why ghc creates different code for
   returnP a = return a
   returnP = return

I put the grammar file online, in case you still want to have a look at it:
http://cs.uiowa.edu/~fuchs/DarwinCS/DarwinCS/Darwin/Tptp/Parser.y

The complete source (compiles with make opt) is here:
http://cs.uiowa.edu/~fuchs/DarwinCS/DarwinCS.tar.gz

And I use it on this input:
http://cs.uiowa.edu/~fuchs/DarwinCS/SYN854-1.p

with the command line:
time Darwin/Main +RTS -sstderr -RTS 600 SYN854-1.p

Sorry about the noise,
	Alexander



More information about the Glasgow-haskell-users mailing list