我用很少的语法添加重建了F#.我能够告诉VS2010将它们用于F#Interactive和构建,但代码编辑器仍然声称我犯了错误(即使项目构建得很好).
甚至可以改变这个吗?如果是 - 怎么样?
假设我有一系列序列,例如
{1, 2, 3}, {1, 2, 3}, {1, 2, 3}
Run Code Online (Sandbox Code Playgroud)
什么是旋转或拉链这个序列的最佳方法,所以我反而拥有,
{1, 1, 1}, {2, 2, 2}, {3, 3, 3}
Run Code Online (Sandbox Code Playgroud)
有没有一种可理解的方式这样做而不诉诸操纵底层IEnumerator<_>类型?
澄清一下,这些是seq<seq<int>>对象.每个序列(内部和外部)可以包含任意数量的项目.
我有一个已经实现了.Item方法的.Net库,例如
namespace Library2
type A() =
member m.Item with get(a: string) = printfn "get a string"
member m.Item with get(a: int) = printfn "simple slice"
Run Code Online (Sandbox Code Playgroud)
在使用此库的代码中,我想添加一个同名的额外方法(因此它是optional extensions):
#r @"Library2.dll"
open Library2
type A with
member m.Item with get(a: bool) =
printfn "get a bool"
Run Code Online (Sandbox Code Playgroud)
以下示例的最后一行无法编译:
let a = new A()
a.["good"]
a.[10]
a.[true]
Run Code Online (Sandbox Code Playgroud)
在F#DOC说:
扩展方法不能是虚方法或抽象方法.它们可以重载其他同名的方法,但是在调用模糊的情况下,编译器会优先使用非扩展方法.
这意味着我无法.ToString/.GetHashCode使用相同类型的签名进行扩展,但在这里我使用了不同类型的签名.为什么新方法无法扩展?
在f#中阅读有关创建新事件的代码,我遇到了两个调用event.Publish和event.Trigger,但是我不太确定它们的含义。你能告诉我他们的工作吗?
请考虑手册中写的内容:
event.Publish将观察结果发布为一流的值。
event.Trigger使用给定的参数触发观察。
由于我是意大利人,因此在这种情况下使用的“观测”一词对我没有任何好处。
对于这个问题,这个问题是一个后续问题:如何在OCaml中进行协变可观察
接受的答案的作者(随便)指出,使用let rec绑定两个独立的值比两个单独的let绑定更"经济" .
let make x =
let queue = Queue.create () in
let obj = x in
let watch f = Queue.add f queue in
let notify () = Queue.iter (fun f -> f x) queue in
{ obj; watch; notify; }
Run Code Online (Sandbox Code Playgroud)
VS
let make x =
let queue = Queue.create () in
let obj = x in
let rec watch f = Queue.add f queue
and notify () = Queue.iter (fun f …Run Code Online (Sandbox Code Playgroud) 我有关于Erlang功能的问题.查看Erlang shell中的代码:
Run Code Online (Sandbox Code Playgroud)1> F1 = fun() -> timer:sleep(1000) end. #Fun<erl_eval.20.111823515> 2> F2 = fun() -> io:format("hello world~n", []) end. #Fun<erl_eval.20.111823515>
F1和F2是不同的,但为什么他们都有标识符#Fun<erl_eval.20.111823515>?这些神奇数字意味着什么?
ERTS手册中有一段说:
When interpreting the data for a process, it is helpful to know that anonymous
function objects (funs) are given a name constructed from the name of the
function in which they are created, and a number (starting with 0) indicating
the number of that fun within that function.
Run Code Online (Sandbox Code Playgroud)
我也抓不住这一段的含义,请你解释一下吗?
我在下面有这个代码:
#![no_main]
pub mod struct_example {
struct Pair {
a: f64,
b: f64,
}
pub fn example () {
println!("##### Struct Example #####");
let pair: Pair = Pair {a: 0.3, b: 0.4};
println!("{} and {}", pair.a, pair.b);
}
}
Run Code Online (Sandbox Code Playgroud)
我试图通过发出以下命令进行编译:
rustc src/structures.rs
Run Code Online (Sandbox Code Playgroud)
我得到的是以下错误:
$ rustc src/structures.rs
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "./structures" "./structures.o" "-Wl,--whole-archive" "-lmorestack" "-Wl,--no-whole-archive" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4e7c5e5c.rlib" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/home/lowks/src/rust/gettingrusty/.rust/lib/x86_64-unknown-linux-gnu" …Run Code Online (Sandbox Code Playgroud) 我对Haskell相对较新,来自F#(一种微软语言).
我已经从脚手架创建了一个Yesod项目,玩了一下,调整了一些东西,然后它停止工作,这个错误消息(在所有模块成功构建之后):
devel.hs: D:\yesod\projects\test101\dist\build\HStest101-0.0.0.o: unknown symbol `___stginit_test101zm0zi0zi0_HandlerziPage_'
devel.hs: devel.hs: unable to load package `test101-0.0.0'
Exit code: ExitFailure 1
Run Code Online (Sandbox Code Playgroud)
通过直接使用阴谋(cabal build,cabal install,dist\build\test101\test101)我是能够运行应用程序,但是这实在是烦人.
我能做什么?
谢谢!
for i in a..b do
res <- res * myarray.[i]
res
Run Code Online (Sandbox Code Playgroud)
我必须使用喜欢
Array.fold (*) 1 (Array.sub myarray a (b - a + 1))
Run Code Online (Sandbox Code Playgroud)
,我认为这是相当慢,而不是那么简洁?
fun sample(list_of_str_lists, s) =
case list_of_str_lists of
[] => []
| x::[] => case (all_except_option(s, x)) of
SOME lst => lst
| NONE => []
| x::xs' => case (all_except_option(s, x)) of
SOME lst => lst @ sample(xs', s)
| NONE => [] @ sample(xs', s)
Run Code Online (Sandbox Code Playgroud)
它使用一个辅助函数,该函数接受一个字符串列表,list option如果该列表中有匹配的字符串(同样,不包括匹配的字符串),则返回该列表中的所有元素。所以辅助函数将接受一个列表["a", "b", "c"]和一个字符串"a",如果匹配"a",将返回一个包含["b", “c”].
我的问题出在sample最后一个模式匹配分支中。它抛出错误
earlier rule(s): 'Z list option -> 'Z list
this rule: string list list -> string list …Run Code Online (Sandbox Code Playgroud)