# Function template vs. polymorphic functions

**URL:** <https://discourse.ats-lang.org/t/function-template-vs-polymorphic-functions/321>\
**Category:** Google Group\
**Created:** [January 17, 2014, 10:52pm UTC](https://discourse.ats-lang.org/t/function-template-vs-polymorphic-functions/321 "2014-01-17T22:52:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [January 17, 2014, 10:52pm UTC](https://discourse.ats-lang.org/t/function-template-vs-polymorphic-functions/321/1 "2014-01-17T22:52:38Z")

</div>

FYI.

A function template is not compiled; only its instances are compiled.

A polymorphic function is compiled once; each call to the polymorphic  
function is linked to the object code generated from compiling the function.

For instance,

fun{a:t@ype} foo (x: a) = x // this is a function template  
fun foo2 {a:type} (x: a) = x // this is a polymorphic function

Often people write the following kind of function:

fun foo3 {a:t@ype} (x: a) = x // a polymorphic function that cannot be  
compiled.

The problem with foo3 is that it cannot be properly compiled to object code  
as the  
size of the type [a] is unknown at compile-time. When in confusion, please  
ask the  
simple question: Can such a function be implemented in C? If the answer is  
negative,  
then the function probably needs to be turned into a function template.
