How do I make a jitclass with a jitted function member?

(moved from gitter)
Is there a way to make a jitclass with a jit function member? In this case I’d like to_be_called to be some kind of pointer/reference to the jit function.

from numba import njit, int64
from numba.experimental import jitclass

@jitclass([("to_be_called", int64)])  # what type goes here?
class Caller:
    def __init__(self, to_be_called):
        self.to_be_called = to_be_called

    def call(self):
        # I'd like to write something like
        # return self.to_be_called()
        return 0

@njit(int64())
def to_be_called_impl():
    return 42

# caller = Caller(to_be_called_impl)
# caller.call()

In the gitter conversation, @stuartarchibald responded:

from numba import njit, int64, typeof
from numba.experimental import jitclass

@njit(int64())
def to_be_called_impl():
    return 42

fty = typeof(to_be_called_impl)

@jitclass([("to_be_called", fty)])
class Caller:
    def __init__(self, to_be_called):
        self.to_be_called = to_be_called

    def call(self):
        return self.to_be_called()

caller = Caller(to_be_called_impl)
print(caller.call())

and @luk-f-a responded with a link to

Thanks for posting @nelson2005, it’s great to have this recorded! Original discussion is here.