convert an ast to a template function