The backend of amb-collect.
amb-collect wraps its parameter into a thunk and passes it into this procedure.