Type error: Unhandled error: apply to not Pi