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