"inline" keyword not accepted next to "fun" keyword
See original GitHub issueRepost of issue Functions defined as a value can’t be inlined where Don Syme suggested to post it here.
The following two definitions are semantically identical and compiled to exactly the same code:
let add (x : int) (y : int) : int =
x + y
let add : int -> int -> int =
fun x y -> x + y
Yet the inline
keyword is not allowed next to fun
while it is allowed next to let
.
That is:
let inline add (x : int) (y : int) : int =
x + y
compiles, but neither
let add : int -> int -> int =
inline fun x y -> x + y
nor
let add : int -> int -> int =
fun inline x y -> x + y
compiles.
I consider this a bug because
let add : int -> int -> int =
fun x y -> x + y
is valid syntax for defining a function, but making it inline
is not supported. It should not make a difference which style I choose. Especially in terms of maintainability - right now - I would have to rewrite the function to add inline
which is a considerable and unnecessary inconvenience.
Issue Analytics
- State:
- Created 8 years ago
- Comments:15 (4 by maintainers)
Top Results From Across the Web
Inline keyword not recognized in c module compiled inside ...
I am developing an embedded C application in a C90-compliant compiler which, on the other hand, for testing and debugging purposes, is deployed ......
Read more >Should you use the inline keyword or not? : r/cpp
AFAIU the inline keyword is not a guarantee, it is just a hint that the compiler can consider the function for inlining. The...
Read more >Inline Functions, C++ FAQ
Therefore the inline keyword should not go within the class's public: (or the protected: or private: ) part, so it needs to go...
Read more >inline, noinline, crossinline — What do they mean?
Say you have multiple lambdas in your inlined function and you don't want all of them to be inlined, you can mark the...
Read more >Inline functions in C++. What's the point?
The “inline” keyword allowed the body of a function (method) to be defined in a header file, hence allowing the compiler to make...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just throwing in my two cents: I’d been meaning to file an issue that you couldn’t do “let inline fn = function | …cases…” for a while, and this issue covers that, so I agree it would be a nice thing to have.
@amazingant @exercitusvir @21c-HK I’m ok with this this adjustment being made to the language (though I don’t particularly favour its use to write F# code in a non-idiomatic style trying to emulate styles of other languages). So I’ve changed the status of the issue on uservoice to “approved” - though I don’t personally plan to work on the adjustment.
I agree with @brodyberg above that the way to address this is for someone to propose a PR. I suggest starting by finding the place where the current error is raised, e.g. by searching FSComp.txt or other files for the error message text.