inline means that whenever an inline function is called the compiler will take the definition of the function and copy it inline at the call site substituting parameters. It is like macro code expansion and the inline keyword from C++.

^a are compile-time type parameters for inline functions. A ^a type parameter is able to have constraints applied to it that a run-time type parameter ('a) could not have. E.g., in this example constraining that the type has a static member called ToInt32, and the type-case you can do with when. Because inline functions are applied at compile-time the compiler is able to check and utilize these constraints.

By on 2/15/2008 9:42 PM ()

Thanks gneverov! I'm curious, are features like code expansion and compile-time type parameters components of compiler theory, or more of a feature of compiled languages from the "C" family?

By on 2/16/2008 5:53 AM ()

Function inlining is concern of every compiled language -- functional or imperative. Some language implementations allow the programmer to specify inline functions, others will internally inline functions based on the compiler's own heuristics. I guess the inline and ^a system in F# is sort of similar to C++ templates (in that you can call methods on a type parameter and this is resolved at compile-time), but unlike C++ templates they are not intended for general programming consumption. I believe the primary reason for these features in F# is to provide a convenient way to implement the run-time library (fslib). So if you're wanting to use this in your own code you should definitely know what you're doing!

By on 2/16/2008 10:23 PM ()

Thanks again! I wanted to get an understanding what was going on "behind" the scenes when I call Int64.of_int x.... It's nice to understand the implementations. But, I don't believe I will get to the detail of having to use inline and ^a in my code! If I ever do, I would have to ask myself, "are you sure this is the best way to solve the problem?"

By on 2/17/2008 6:59 AM ()

Hi,
Inline tells the compiler to optimize the code,but I don't know its internals.

When your F# code compiles, it compiles to IL. So CLR executes all the time. When you write IL instructions in your code, your bindings are compiled with the associated IL. Then CLR executes the code again.

By on 2/15/2008 6:19 PM ()

Thanks Certen - makes sense, what a cool feature, not that I'll proabably ever use it! Any idea on the ^a syntax?

By on 2/15/2008 6:56 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper