[英]Functional languages targeting the LLVM
Are there any languages that target the LLVM that: 是否有任何针对LLVM的语言:
Scala is all of these, but only targets the JVM. Scala就是所有这些,但只针对JVM。 F# (and to some extent C#) is most if not all of these, but only targets .NET. F#(在某种程度上是C#)是大多数(如果不是全部),但仅针对.NET。 What similar language targets the LLVM? 什么类似的语言针对LLVM?
There's a Haskell (GHC) backend targeting the LLVM. 有一个针对LLVM的Haskell(GHC)后端 。
You could also try using F# through Mono-LLVM . 您也可以尝试使用F#通过Mono-LLVM 。
Also, the VMKit project is implementing both the JVM and the .NET CLI on top of LLVM; 此外, VMKit项目在LLVM之上实现JVM和.NET CLI; it's still in its early stages but once it matures you could use it with F#, or any JVM-targeting functional languages (Scala, Clojure, etc.) 它仍处于早期阶段,但一旦成熟,您可以将它与F#或任何面向JVM的功能语言(Scala,Clojure等)一起使用
I'm not sure how far these have progressed, but they may be worth adding to the list: 我不确定这些进展有多远,但它们可能值得添加到列表中:
Scala for LLVM - https://github.com/greedy/scala/ 用于LLVM的Scala - https://github.com/greedy/scala/
Timber for LLVM - https://bitbucket.org/capitrane/timber-llvm 木材用于LLVM - https://bitbucket.org/capitrane/timber-llvm
Mono for LLVM - http://www.mono-project.com/Mono_LLVM LLVM的单声道 - http://www.mono-project.com/Mono_LLVM
Yes... clang . 是的...... 铿锵 C++ has everything on your list except for list comprehensions. 除了列表推导之外,C ++包含列表中的所有内容。 It is also the flagship LLVM language. 它也是旗舰LLVM语言。
"Are statically typed" “是静态类型的”
Yup 对
"Use type inference" “使用类型推断”
// local type inference
auto var = 10;
// type inference on parameters to generic functions
template <typename T>
void my_function(T arg) {
...
}
my_function(1) // infers that T = int
// correctly handles more complicated cases where type is partially specified.
template <typename T>
void my_function(std::vector<T> arg) {
...
}
std::vector<int> my_vec = {1, 2, 3, 4};
my_function(my_vec) // infers that T = int
"Are functional (ie lambda expressions, closures, list primitives, list comprehensions, etc.)" “是功能性的(即lambda表达式,闭包,列表原语,列表推导等)”
Lambdas in c++ look like [capture_spec](arglist...) { body }
. c ++中的[capture_spec](arglist...) { body }
看起来像[capture_spec](arglist...) { body }
。 You can either capture closed over variables by reference (similar to lisp) like so: [&]. 您可以通过引用(类似于lisp)捕获已关闭的变量,如下所示:[&]。 Alternatively you can capture by value like so: [=]. 或者,您可以按值捕获:[=]。
int local = 10;
auto my_closure = [&]() { return local;};
my_closure(); // returns 10.
In C++ map, zip, and reduce are called std::transform and std::accumulate. 在C ++中,map,zip和reduce被称为std :: transform和std :: accumulate。
std::vector<int> vec = {1, 2, 3, 4};
int sum = std::accumulate(vec.begin(), vec.end(), [](int x, int y) { return x + y; });
You can also rig up list comprehensions using a macro and and a wrapper around std::transform if you really want... 如果你真的想要的话,你还可以使用宏和std :: transform的包装来装配列表推导...
"Have first class object-oriented features (inheritance, polymorphism, mixins, etc.)" “拥有一流的面向对象特性(继承,多态,混合等)”
Of course. 当然。 C++ allows virtual dispatch + multiple inheritance + implementation inheritance. C ++允许虚拟调度+多继承+实现继承。 Note: mixins are just implementation inheritance. 注意:mixins只是实现继承。 You only need a special "mixin" mechanism if your language prohibits multiple inheritance. 如果您的语言禁止多重继承,您只需要一个特殊的“mixin”机制。
"Have a sophisticated type system (generics, covariance and contravariance, etc.)" “有一个复杂的类型系统(泛型,协方差和逆变等)”
C++ templates are the most powerful generics system in any language as far as I know. 据我所知,C ++模板是任何语言中最强大的泛型系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.