function template vs. polymorphic functions

15 views
Skip to first unread message

gmhwxi

unread,
Jan 17, 2014, 5:52:38 PM1/17/14
to ats-lan...@googlegroups.com
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.

Reply all
Reply to author
Forward
0 new messages