function pointers type polymorphism through composition and static lifetime #10

Open
opened 2026-04-17 00:08:14 +00:00 by jaynuine · 2 comments
Owner

currently, methods such as array::get and array::fold operate with either statically typed functions as arguments or generic indirect monads

since we need to establish singular, complete types for both the return value and each argument of a function, the current workaround is to rely on indirection, accepting and returning pointers to undisclosed data

the issue being that direct functions must be wrapped into indirect functions which are then able to be passed to pearr methods, and that is incredibly convoluted and messy

array::fold for instance expects a sizer function returning a definite data type directly ; however, attempting to pass such a function to one of map or iter or mutate is not possible, as those ought to expect indirect functions, ergo accept a pointer returning monad and copy from that pointer stride bytes (the next argument)
these methods need not know the exact type, all they need is some way to isolate the memory region of a function call (which we realise by passing a function reference, and the size of its return type as the stride)
but in order for fold to exploit its sizer, it ought be wrapped in a layer of indirection before being fed to a map-like function, which involves

  • either storing the data from the direct function in a static buffer and returning the address of that variable (or heap allocating)
  • or dereferencing the result of an indirect function call by casting it to a pointer of the expect type on a per call basis, outside of the method itself
currently, methods such as array::get and array::fold operate with either statically typed functions as arguments or generic indirect monads since we need to establish singular, complete types for both the return value and each argument of a function, the current workaround is to rely on indirection, accepting and returning pointers to undisclosed data the issue being that direct functions must be wrapped into indirect functions which are then able to be passed to pearr methods, and that is incredibly convoluted and messy array::fold for instance expects a sizer function returning a definite data type directly ; however, attempting to pass such a function to one of `map` or `iter` or `mutate` is not possible, as those ought to expect indirect functions, ergo accept a pointer returning monad and copy from that pointer stride bytes (the next argument) these methods need not know the exact type, all they need is some way to isolate the memory region of a function call (which we realise by passing a function reference, and the size of its return type as the stride) but in order for fold to exploit its sizer, it ought be wrapped in a layer of indirection before being fed to a map-like function, which involves - either storing the data from the direct function in a static buffer and returning the address of that variable (or heap allocating) - or dereferencing the result of an indirect function call by casting it to a pointer of the expect type on a per call basis, outside of the method itself
Author
Owner

to address this, one may consider composing the sizer function with an "addrof" function, instead of declaring a new static function with every function needing to be composed, and passing a reference to that instead

is that even possible in c

to address this, one may consider composing the sizer function with an "addrof" function, instead of declaring a new static function with every function needing to be composed, and passing a reference to that instead is that even possible in c
Author
Owner

i have great news

i have great news
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaynuine/pearr#10
No description provided.