在F#中,我希望得到一个相当标准的抽象数据类型:
// in ADT.fsi
module ADT
type my_Type
// in ADT.fs
module ADT
type my_Type = int
Run Code Online (Sandbox Code Playgroud)
换句话说,模块内部的代码知道my_Type是int,但外部代码不是.但是,F#似乎有一个限制,其中特定的缩写不能被签名隐藏.此代码给出了编译器错误,此处描述了限制.
如果my_Type是一个有区别的联合,那么就没有编译器错误.我的问题是,为什么限制?我似乎记得能够在SML和Ocaml中做到这一点,而且,在创建抽象数据类型时,这不是一个非常标准的事情吗?
谢谢
我想使用boost属性树write_json序列化,这样可以节省一切为字符串,这并不是说数据是错误的,但我需要每次都明确地投下他们,我想别的地方使用它们.(比如在python或其他C++ json(非boost)库中)
这里是一些示例代码以及我根据区域设置得到的内容:
boost::property_tree::ptree root, arr, elem1, elem2;
elem1.put<int>("key0", 0);
elem1.put<bool>("key1", true);
elem2.put<float>("key2", 2.2f);
elem2.put<double>("key3", 3.3);
arr.push_back( std::make_pair("", elem1) );
arr.push_back( std::make_pair("", elem2) );
root.put_child("path1.path2", arr);
std::stringstream ss;
write_json(ss, root);
std::string my_string_to_send_somewhare_else = ss.str();
Run Code Online (Sandbox Code Playgroud)
并且my_string_to_send_somewhere_else是某事.像这样:
{
"path1" :
{
"path2" :
[
{
"key0" : "0",
"key1" : "true"
},
{
"key2" : "2.2",
"key3" : "3.3"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
反正是将它们保存为值,例如:
"key1" : true或"key2" : 2.2?
我处于一个愚蠢的境地:我在TRUNK的工作副本中做了一些改变.由于尚未测试更改,我想将所有更改传输到分支.根据Tortoise的手册,Switch将失去我的所有修改.有没有办法在工作副本中保留我的更改并将它们保存在存储库的分支中.
我正在尝试在我的网站上使用新的Facebook Graph API.这就是我所拥有的:
在页面的某个地方:
<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button>
Run Code Online (Sandbox Code Playgroud)
标签后面:
<div id="fb-root">
</div>
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({ appId: '<%= ConfigurationManager.AppSettings["FBAppId"] %>', status: true, cookie: true, xfbml: true });
/* All the events registered */
FB.Event.subscribe('auth.login', function (response) {
// do something with response
alert("login success");
});
FB.Event.subscribe('auth.logout', function (response) {
// do something with response
alert("logout success");
});
FB.getLoginStatus(function (response) {
if (response.session) {
// logged in and connected user, someone you know
alert("login success");
}
});
}; …Run Code Online (Sandbox Code Playgroud) 如purify和valgrind等内存泄漏检测工具如何工作?
如何设计和实现我自己的工具?
我知道这可能有点奇怪,但怀疑是一个疑问...在下列情况下会发生什么......
private void SendMail()
{
try
{
//i try to send a mail and it throws an exception
}
catch(Exception ex)
{
//so i will handle that exception over here
//and since an exception occurred while sending a mail
//i will log an event with the eventlog
//All i want to know is what if an exception occurs here
//while writing the error log, how should i handle it??
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
有没有办法在C#中将UTF-8字符串转换为简体中文(GB2312).任何帮助是极大的赞赏.
关心Jyothish George
我想在UITableView中显示多个列.
例如:
的TableView
FName LName Age
----- ----- ---
Abby Michale 34
Run Code Online (Sandbox Code Playgroud) 我不太清楚如何做到这一点.我需要使用正则表达式验证电子邮件地址,如下所示:
[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)
Run Code Online (Sandbox Code Playgroud)
然后我需要在这样的jQuery函数中运行它:
$j("#fld_emailaddress").live('change',function() {
var emailaddress = $j("#fld_emailaddress").val();
// validation here?
if(emailaddress){}
// end validation
$j.ajax({
type: "POST",
url: "../ff-admin/ff-register/ff-user-check.php",
data: "fld_emailaddress="+ emailaddress,
success: function(msg)
{
if(msg == 'OK') {
$j("#fld_username").attr('disabled',false);
$j("#fld_password").attr('disabled',false);
$j("#cmd_register_submit").attr('disabled',false);
$j("#fld_emailaddress").removeClass('object_error'); // if necessary
$j("#fld_emailaddress").addClass("object_ok");
$j('#email_ac').html(' <img src="img/cool.png" align="absmiddle"> <font color="Green"> Your email <strong>'+ emailaddress+'</strong> is OK.</font> ');
} else {
$j("#fld_username").attr('disabled',true);
$j("#fld_password").attr('disabled',true);
$j("#cmd_register_submit").attr('disabled',true);
$j("#fld_emailaddress").removeClass('object_ok'); // if necessary
$j("#fld_emailaddress").addClass("object_error");
$j('#email_ac').html(msg);
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
验证在哪里以及表达式是什么?
从二进制文件中读取两个日期时,我看到以下错误:
“输出字符缓冲区太小,无法包含解码的字符,编码 'Unicode (UTF-8)' 回退 'System.Text.DecoderReplacementFallback'。参数名称:chars”
我的代码如下:
static DateTime[] ReadDates()
{
System.IO.FileStream appData = new System.IO.FileStream(
appDataFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
List<DateTime> result = new List<DateTime>();
using (System.IO.BinaryReader br = new System.IO.BinaryReader(appData))
{
while (br.PeekChar() > 0)
{
result.Add(new DateTime(br.ReadInt64()));
}
br.Close();
}
return result.ToArray();
}
static void WriteDates(IEnumerable<DateTime> dates)
{
System.IO.FileStream appData = new System.IO.FileStream(
appDataFile, System.IO.FileMode.Create, System.IO.FileAccess.Write);
List<DateTime> result = new List<DateTime>();
using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(appData))
{
foreach (DateTime date in dates)
bw.Write(date.Ticks);
bw.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
可能是什么原因?谢谢