POV-Ray : Newsgroups : povray.off-topic : Found the dynamic optimization things... : Re: Found the dynamic optimization things... Server Time
30 Sep 2024 19:26:02 EDT (-0400)
  Re: Found the dynamic optimization things...  
From: Invisible
Date: 24 Sep 2008 09:44:49
Message: <48da4451$1@news.povray.org>
Warp wrote:

>   You didn't understand me. The line "foldl1 (+) someList" is *in* the
> precompiled library. It was not written by the user.

Ah, I see.

Well "foldl1 (+)" is the implementation of "sum", which is indeed in the 
Haskell standard library (and hence precompiled). So what you're asking 
is, "what happens if I call 'sum' on some custom datatype that I just 
wrote?"

>   Exactly where is this virtual table pointer stored?

Each time you create a datatype that supports (+), (-), etc., the 
compiler generates a table pointing to the appropriate implementations 
of these functions for that datatype.

Each time you compile a function that accepts an arbitrary numeric type, 
the compiler secretly adds an extra pointer argument to that function. 
When a caller calls that function, the compiler secretly adds a pointer 
to the correct table into the function call. (And as I noted, if the 
caller doesn't know the type, it must have received a pointer itself in 
the same way, so it just passes that on.)

If that makes sense?


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.