我目前正在尝试在Windows操作系统上安装和更新一些软件包.唯一的问题是我使用Cygwin来通过终端键入命令(我知道,我可以在Cygwin上键入Linux类型的命令,如cd,ls等 - 我可能错了).但是,当我尝试安装包如:
sudo apt-get install paparazzi-dev
Run Code Online (Sandbox Code Playgroud)
我得到了答复:
-sh: sudo: command not found.
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?
我偶然发现了可以在F#中定义自定义运算符的事实.另外,我相信可以在C#中重用F#代码.
是否可以在F#中创建自定义运算符,在C#中引用项目然后在C#中重用运算符?例如,假设我要将.?运算符定义为F#中的某些内容,那么我可以在C#项目中以某种方式重用它吗?
我是F#和函数式编程的新手.给定一个场景,您希望迭代序列或字符串列表,并将其映射到不同类型的新列表,使用累加器,什么是正确的函数方法?我可以使用可变变量在F#中实现这一点,但我很难找到适合这个的函数.它与我认为的地图类似,但有国家的概念.
换句话说,我想将一个字符串列表转换为一个win表格单选按钮列表,但是对于每个新按钮,我想将20添加到前一个y坐标.就像是:
new RadioButton(Text=str,Location=new Point(20,y+20),Width=350)
Run Code Online (Sandbox Code Playgroud) Redux文档说我应该创建动作和动作创建者,如下所示:
function addTodo(filter) {
return {
type: SET_VISIBILITY_FILTER,
filter
}
}
Run Code Online (Sandbox Code Playgroud)
然后写减速器,像这样:
function todoApp(state = initialState, action) {
switch (action.type) {
case SET_VISIBILITY_FILTER:
return Object.assign({}, state, {
visibilityFilter: action.filter
});
}
}
Run Code Online (Sandbox Code Playgroud)
然后我使用dispatch调用该操作:
store.dispatch(addTodo("Ask question on stackoverflow"));
Run Code Online (Sandbox Code Playgroud)
似乎行动和减速器之间存在一对一的对应关系; 该操作的唯一目的是选择减速器并为该减速器提供输入数据.
为什么我们不跳过中间人并用减速器和具有减速器功能的动作创建器识别动作?然后dispatch将采用单个参数,类型的reducer/action State => State:
// Action/reducer. (Parametrised state transformer, really.)
const addTodo = text => state => {
return Object.assign({}, state, {
visibilityFilter: action.filter
});
}
// Dispatch takes as a argument the action/reducer
store.dispatch(addTodo("Ask question on …Run Code Online (Sandbox Code Playgroud) 旧系统会向我发送以下内容:
POST /xml HTTP/1.1
Host: localhost:9000
User-Agent: curl/7.64.1
Accept: */*
Content-Length: 321
Content-Type: multipart/mixed; boundary=------------------------a9dd0ab37a224967
--------------------------a9dd0ab37a224967
Content-Disposition: attachment; name="part1"
Content-Type: text/xml
<foo>bar</foo>
--------------------------a9dd0ab37a224967
Content-Disposition: attachment; name="part2"
Content-Type: application/json
{'foo': 'bar'}
--------------------------a9dd0ab37a224967--
Run Code Online (Sandbox Code Playgroud)
我需要将第一部分解释为原始XElement;对于第二部分,我想要通常的模型绑定。
我试试这个:
POST /xml HTTP/1.1
Host: localhost:9000
User-Agent: curl/7.64.1
Accept: */*
Content-Length: 321
Content-Type: multipart/mixed; boundary=------------------------a9dd0ab37a224967
--------------------------a9dd0ab37a224967
Content-Disposition: attachment; name="part1"
Content-Type: text/xml
<foo>bar</foo>
--------------------------a9dd0ab37a224967
Content-Disposition: attachment; name="part2"
Content-Type: application/json
{'foo': 'bar'}
--------------------------a9dd0ab37a224967--
Run Code Online (Sandbox Code Playgroud)
但 ASP.NET 不允许使用[FromBody].
如何让我的 ASP.NET Core 服务接收带有 content-type 的 http 请求multipart/mixed?
我需要一个支持的类似数组的数据结构
a.[i]
Run Code Online (Sandbox Code Playgroud)
在时间O(1)和
a.[i..j]
Run Code Online (Sandbox Code Playgroud)
也及时O(1).
O(1)更新不是必需的.实际上,我需要的是一个具有就地切片或子阵列概念的常量数组.
我当然可以构建这样的东西Array,但如果我可以使用已存在的东西,我会更高兴吗?
在Mac OS上使用mono,如果我编译并配置下面的程序,我会得到以下结果:
% fsharpc --nologo -g foo.fs -o foo.exe
% mono --profile=default:stat foo.exe
...
Statistical samples summary
Sample type: cycles
Unmanaged hits: 336 (49.1%)
Managed hits: 349 (50.9%)
Unresolved hits: 1 ( 0.1%)
Hits % Method name
154 22.48 Microsoft.FSharp.Collections.SetTreeModule:height ...
105 15.33 semaphore_wait_trap
74 10.80 Microsoft.FSharp.Collections.SetTreeModule:add ...
...
Run Code Online (Sandbox Code Playgroud)
注意第二个条目,semaphore_wait_trap.这是程序:
[<EntryPoint>]
let main args =
let s = seq { 1..1000000 } |> Set.ofSeq
s |> Seq.iter (fun _ -> ())
0
Run Code Online (Sandbox Code Playgroud)
我查看了Set模块的源代码,但我没有发现任何(明显的)锁定.
我的单线程程序真的花了15%的执行时间搞乱信号量吗?如果是,我可以让它不这样做并获得性能提升吗?
这个程序:
type A = { a : int }
type B = { b : A }
//34567890
let r = {
b = { // line 6
a = 2 // line 7
}
}
Run Code Online (Sandbox Code Playgroud)
在mono/fsharpc下产生两次这样的警告:
/Users/debois/git/dcr/foo.fs(7,5):警告FS0058:可能的错误缩进:此标记在位置(6:7)处开始的上下文越位.尝试进一步缩进此标记或使用标准格式约定.
为什么会出现这种警告?在F#-spec页.228让我觉得'{'后面的标记'a'设置了一个新的越位线,在这种情况下应该没有问题?
为什么会出现两次?
谢谢,
索伦
全输出:
dcr > fsharpc foo.fs
F# Compiler for F# 3.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License
/Users/debois/git/dcr/foo.fs(7,5): warning FS0058: Possible incorrect indentation: this token is offside of context …Run Code Online (Sandbox Code Playgroud) 在回答这个问题compare时,我发现了受歧视工会的以下行为。
type T = A | B | C | D
compare A B (* val it : int = -1 *)
compare A C (* val it : int = -2 *)
compare A D (* val it : int = -3 *)
Run Code Online (Sandbox Code Playgroud)
我对此感到惊讶。
我可以compare像这样测量构造函数之间的“距离”吗?
规范说(第 154 页)关于生成的compareTo:
如果 T 是联合类型,则首先对两个值的联合案例的索引调用 Microsoft.FSharp.Core.Operators.compare,然后对联合案例携带的数据的 x 和 y 的每个相应字段对调用。返回第一个非零结果。
由此,我希望compare类型T总是给出其中之一,-1,0,1因为这就是compare数字类型的行为方式。(正确的?)
我在这里有一些F#代码用于递归函数,它将列表向左旋转n.我是F#的新手,我正在寻找一种修改此代码的方法,不仅可以按n位置输出一次旋转,还可以输出所有可能的旋转.
例如,假设我有列表:
let list1 = [1; 2; 3; 4]
Run Code Online (Sandbox Code Playgroud)
我想在此列表上调用rotate,以便输出为:
[ [1; 2; 3; 4]; [2; 3; 4; 1]; [3; 4; 1; 2]; [4; 1; 2; 3] ]
Run Code Online (Sandbox Code Playgroud)
我有左移n的代码是:
let rec rotate xs k =
match xs, k with
|[], _ -> []
|xs, 0 -> xs
|x::xs, k when k > 0 -> rotate(xs @ [x])(k-1)
|xs, k -> rotate xs (List.length xs + k)
Run Code Online (Sandbox Code Playgroud)
我不知道如何编辑它来执行上面列出的步骤.任何帮助或资源将不胜感激.我应该补充一点,我真的希望函数是递归的.谢谢.