Functorise over memory allocator