在过去的几年里,F#已经演变成微软完全支持的语言之一,采用了在OCaml,ML和Haskell中孵化的许多想法.
在过去几年中,C#通过引入越来越多的功能语言功能扩展了其通用功能:LINQ(列表理解),Lambdas,闭包,匿名代表等等......
鉴于C#采用这些功能特性和F#的分类法作为一种不纯的函数式语言(它允许您在调用函数时访问框架库或更改共享状态),两种语言之间存在很强的相似性,尽管每种语言都有自己的极端主要强调.
我对您在制作多语言程序中使用这两种语言的任何成功模型以及您在过去一年中使用F#编写的生产软件(Web应用程序,客户端应用程序,服务器应用程序)中的区域感兴趣用C#编写.
我正在尝试定义任何跨越ghci中多行的简单函数,以下面的示例为例:
let abs n | n >= 0 = n
| otherwise = -n
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已尝试在第一行后按Enter键:
Prelude> let abs n | n >= 0 = n
Prelude> | otherwise = -n
<interactive>:1:0: parse error on input `|'
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用:{和:}命令但是我没有做到这一点:
Prelude> :{
unknown command ':{'
use :? for help.
Run Code Online (Sandbox Code Playgroud)
我在Linux上使用GHC Interactive版本6.6 for Haskell 98,我缺少什么?
考虑到这个JavaScript"类"定义,这是我能想到的最好的方法来解决这个问题:
var Quota = function(hours, minutes, seconds){
if (arguments.length === 3) {
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
this.totalMilliseconds = Math.floor((hours * 3600000)) + Math.floor((minutes * 60000)) + Math.floor((seconds * 1000));
}
else if (arguments.length === 1) {
this.totalMilliseconds = hours;
this.hours = Math.floor(this.totalMilliseconds / 3600000);
this.minutes = Math.floor((this.totalMilliseconds % 3600000) / 60000);
this.seconds = Math.floor(((this.totalMilliseconds % 3600000) % 60000) / 1000);
}
this.padL = function(val){
return (val.toString().length === 1) ? "0" + val : val;
}; …Run Code Online (Sandbox Code Playgroud) 我有一个预先存在的mysql数据库,包含大约50个表.
而不是为每个表手动编写一个声明式样式SqlAlchemy类(如此处所示),是否有一个工具/脚本/命令我可以针对mysql数据库运行,它将为数据库中的每个表生成声明式样式的python类?
仅以一个表为例(将为所有50个理想情况生成),如下所示:
+---------+--------------------+
| dept_no | dept_name |
+---------+--------------------+
| d009 | Customer Service |
| d005 | Development |
| d002 | Finance |
| d003 | Human Resources |
| d001 | Marketing |
| d004 | Production |
| d006 | Quality Management |
| d008 | Research |
| d007 | Sales |
+---------+--------------------+
Run Code Online (Sandbox Code Playgroud)
是否有工具/脚本/命令可以生成包含以下内容的文本文件:
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Department(Base):
__tablename__ = 'departments'
dept_no = Column(String(5), primary_key=True) …Run Code Online (Sandbox Code Playgroud) 鉴于:
typedef type-declaration synonym;
Run Code Online (Sandbox Code Playgroud)
我可以看到:
typedef long unsigned int size_t;
Run Code Online (Sandbox Code Playgroud)
声明size_t为同义词long unsigned int,但我(知道它确实如此)无法确切地看到如何:
typedef int (*F)(size_t, size_t);
Run Code Online (Sandbox Code Playgroud)
声明F为.的同义词pointer to function (size_t, size_t) returning int
typedef (type-declaration, synonym)在第一个例子中的两个操作数是long unsigned int和size_t.
在声明中F是否存在typedef的两个参数,或者是否存在typedef的重载版本?
如果C和C++之间存在相关区别,请详细说明,否则我主要对C++感兴趣,如果这有帮助的话.
整个测试代码包含在main.cpp中,如下所示:
#include <iostream>
using std::cout;
using std::endl;
void f(int i) {
int* pi = new int;
*pi = i;
std::cout << "*pi = " << *pi << std::endl;
}
int main(int argc, char *argv[]) {
int i = 0;
while (i < 10000) {
f(i);
++i;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我编译没有优化-O0(来自Eclipse Qt项目):
g++ -c -pipe -O0 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -Irelease -o release/main.o main.cpp
Run Code Online (Sandbox Code Playgroud)
然后链接如下:
g++ -Wl,-O0 -o test release/main.o …Run Code Online (Sandbox Code Playgroud) 如何使用boost或stl创建lambda函数以匹配第三段代码中的boost::function预期参数?Fmain
#include <iostream>
#include <boost/function.hpp>
void F(int a, boost::function<bool(int)> f) {
std::cout << "a = " << a << " f(a) = " << f(a) << std::endl;
}
bool G(int x) {
return x == 0;
}
int main(int arg, char** argv) {
// C++0x
F(123, [](int i) { return i==0; } );
// Using seperate function
F(0, &G);
// How can I do it in place without C++0x
F(123, /* create a lambda here to …Run Code Online (Sandbox Code Playgroud) 使下面所有注释代码以标准C++/Qt方式工作的最佳方法是什么?
class A {
public:
A() { }
virtual ~A() { }
virtual QString toString() { return "A"; }
};
class B: A {
public:
B() { }
~B() { }
QString toString() { return "B"; }
};
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
A a_;
B b_;
// qDebug() << a_; // I can make this work by overloading << yes?
// qDebug() << b_;
// QString x = a_; // How do I …Run Code Online (Sandbox Code Playgroud) 给出以下JavaScript"类"定义:
var Quota = function(totalMinutes){
this.totalMinutes = parseInt(totalMinutes || 0, 10);
};
Quota.prototype.valueOf = function(){
return this.totalMinutes;
};
Quota.prototype.toString = function(format){
format = format || "hh:mm";
return format.replace.call(this, /hh?|mm?/g, function(match){
switch (match) {
case "hh":
return this.totalMinutes * 60;
case "mm":
return this.totalMinutes;
}
});
};
Run Code Online (Sandbox Code Playgroud)
你能否详细解释下面为什么打电话给toString()......
var q1 = new Quota(60);
console.log( q1.toString() );
Run Code Online (Sandbox Code Playgroud)
...导致出现以下错误:
InternalError:过多的递归{message ="过多的递归",更多...}
我在Firebug控制台中运行代码(Firefox 3.5.7 + Firebug 1.5).理想情况下,我想知道递归回调的位置toString()以及关于如何通过call或执行替换功能的建议apply