我尝试在C#中编译以下代码:
public static T FirstEffective(IEnumerable<T> list)
{
Predicate<T> pred = x => x != null;
return Enumerable.FirstOrDefault(list, pred);
}
Run Code Online (Sandbox Code Playgroud)
编译器(Mono/.NET 4.0)给出以下错误:
File.cs(139,47) The best overloaded method match for `System.Linq.Enumerable.FirstOrDefault<T>(this System.Collections.Generic.IEnumerable<T>,System.Func<T,bool>)' has some invalid arguments
/usr/lib/mono/4.0/System.Core.dll (Location of the symbol related to previous error)
File.cs(139,47): error CS1503: Argument `#2' cannot convert `System.Predicate<T>' expression to type `System.Func<T,bool>'
Run Code Online (Sandbox Code Playgroud)
这是相当奇怪的,因为a Predicate<T>实际上是一个函数,它接受一个参数作为输入T并返回一个bool(T甚至是"协变"因此T允许的特化).代表们是否不考虑"Liskov替代原则"来推导出Predicate<T>相当于Func<T,bool>?据我所知,这个等价问题应该是可判定的.
什么是惯用的方式Double -> Float?
是uncurry encodeFloat . decodeFloat吗?
(我正在使用gloss,这需要Floats)
找到这些问题答案的推荐方法是什么?
我正在尝试这个hoogle查询,但答案都非常无益(尝试一下 - 它unsafeCoerce位于列表的顶部)
我的第一个想法是写一个interator,或者做一些列表理解.但是,就像我在python中编写的每个5-10行方法一样,有人通常可以指示我在标准库中调用来完成相同的操作.
我如何从两个元组x和y一个字典z?
x = ( 1, 2, 3 )
y = ( 'a', 'b', 'c')
z = { }
for index, value in enumerate(y):
z[value] = x[index]
print z
# { 'a':1, 'b':2, 'c':3 }
Run Code Online (Sandbox Code Playgroud) 如何按字母顺序对整数进行排序?像这样:
integers = [10, 1, 101, 2, 111, 212, 100000, 22, 222, 112, 10101, 1100, 11, 0]
Run Code Online (Sandbox Code Playgroud)
在Python控制台上打印如下
[0, 1, 10, 100000, 101, 10101, 11, 1100, 111, 112, 2, 212, 22, 222]
Run Code Online (Sandbox Code Playgroud)
我试过这个
def sort_integers(integers):
return sorted(integers)
Run Code Online (Sandbox Code Playgroud)
但我想你必须这样做
def sort_integers(integers):
return sorted(integers, key = lambda....... )
Run Code Online (Sandbox Code Playgroud)
我只是不知道在lambda之后要写什么?
我写了一个简单的模块叫做Test:
module Test (main) where
main =
putStrLn "Hello"
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试通过以下命令行编译它时:
ghc Test.hs -o my-program
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
[1 of 1] Compiling Test ( Test.hs, Test.o )
<no location info>: error:
output was redirected with -o, but no output will be generated because there is no Main module.
Run Code Online (Sandbox Code Playgroud) 我正在使用CodeCompileUnit并CSharpCodeProvider生成一些源代码.它将下面的标题添加到所有生成的代码中.有没有办法自定义评论,所以它说了别的什么?
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3053
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
Run Code Online (Sandbox Code Playgroud) 当我尝试从第三方SDK编译一些代码时,我收到以下错误.
*Description Resource Path Location Type
deleting object of polymorphic class type ‘Vendor_sys::VendorCode’ which has non-virtual destructor might cause undefined behaviour [-Werror=delete-non-virtual-dtor] PnServer.cpp /PCounter line 467 C/C++ Problem*
Run Code Online (Sandbox Code Playgroud)
我不知道是否可以通过对Vendor SDK的部分了解来满足这个条件,其中大部分繁重工作都是在dll或库对象中完成的.
我的构建环境是带有gpp的Eclipse Juno.
我在Google中搜索了错误消息,但未找到此错误的任何实例.
那么,如果我不能修改供应商代码的黑盒子部分,我的选择是什么?
以下是make过程中失败的代码:
delete pData->unit;
Run Code Online (Sandbox Code Playgroud) 所有string.Split方法似乎都返回一个字符串数组(string[]).
我想知道是否有一个惰性变体返回一个IEnumerable<string>大字符串(或无限长度IEnumerable<char>),当一个人只对第一个子序列感兴趣时,一个节省计算工作量和内存.如果字符串由设备/程序(网络,终端,管道)构成,并且因此不需要立即完全可用,则它也可能是有用的.这样人们就已经可以处理第一次出现了.
.NET框架中是否有这样的方法?
下面当我尝试哈希一个列表时,它给了我一个错误但是使用了一个元组.猜猜它与不变性有关.有人可以详细解释一下吗?
名单
x = [1,2,3]
y = {x: 9}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
Run Code Online (Sandbox Code Playgroud)
元组
z = (5,6)
y = {z: 89}
print(y)
{(5, 6): 89}
Run Code Online (Sandbox Code Playgroud) 我有一个模型预订,其中有一个历史.像这样,我使用django_simple_history
class Booking(CreatedAtAbstractBase):
history = HistoricalRecords()
Run Code Online (Sandbox Code Playgroud)
我使用管理命令来完成任务.我想在预订时预取历史记录
booking_p_history = Booking.history.filter(s_id=6).order_by(
'updated_at').first()
booking_obj_list = Booking.objects.select_related(...) \
.prefetch_related(
Prefetch('booking_history', queryset=booking_p_history, to_attr='driver_pickup_history')
,'booking_history') \
.filter(...)
Run Code Online (Sandbox Code Playgroud)
如何在预取中使用简单的历史记录?
python ×4
c# ×3
haskell ×2
.net ×1
c++ ×1
coercion ×1
delegates ×1
destructor ×1
dictionary ×1
django ×1
enumerator ×1
function ×1
ienumerable ×1
inheritance ×1
predicate ×1
prefetch ×1
sorting ×1
string ×1
tuples ×1