POV-Ray : Newsgroups : povray.off-topic : Found the dynamic optimization things... : Re: Found the dynamic optimization things... Server Time
30 Sep 2024 19:26:58 EDT (-0400)
  Re: Found the dynamic optimization things...  
From: Warp
Date: 24 Sep 2008 09:28:43
Message: <48da408a@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> >   However, how does haskell manage to do this? Suppose you have something
> > like this precompiled into a dynamically loadable library:
> > 
> > foldl1 (+) someList
> > 
> >   Also assume the user has defined his own element type for the list and
> > the (+) function for that element type, and then calls the dynamically
> > loaded library by giving it a list with elements of that type. How does
> > the library know which (+) function to call? How does it know that a (+)
> > function exists for that element type in the first place?

> The foldl1 function expects a list and a function that can operate on 
> the elements of that list. In this case, all that happens is that the 
> *caller* passes foldl1 a pointer to the appropriate implementation of 
> (+) for the data type in question. The foldl1 function itself knows 
> nothing about this; it's up to the caller. Since the caller presumably 
> "knows about" this user-defined data type, that's no problem.

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

  When you are compiling the library you don't know what the type of
elements are in the list nor what is the correct (+) function to call
for those types.

> To summarise: if a type is statically known, the correct function is 
> looked up at compile time. If a type is unknown at compile time, a 
> virtual table pointer is secretly passed in.

  Exactly where is this virtual table pointer stored?

-- 
                                                          - Warp


Post a reply to this message

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