我注意到如果我用StructLayout.Sequential定义一个结构,就像这样:
open System.Runtime.InteropServices
[<StructLayout(LayoutKind.Sequential, Pack=1)>]
type SomeType =
val mutable Field1: uint32
val mutable Field2: uint32
Run Code Online (Sandbox Code Playgroud)
这在实际程序中编译并正常工作,但FSI给出了错误 error FS0193: internal error: Could not load type 'SomeType' from assembly 'FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because field 'Field1' was not given an explicit offset.
这是FSI的错误或限制吗?有解决方法吗?
let iter2D (map: 'T byref -> unit) (arr: 'T[][]) =
for y = 0 to arr.Length - 1 do
let row = arr.[y]
for x = 0 to row.Length - 1 do
let mutable elem = arr.[y].[x]
map &elem
Run Code Online (Sandbox Code Playgroud)
最后一行有:"此时不能使用变量'elem'的地址." 怎么了?
给定以下xs和ys集合:
xs = [8294400,2073600,921600,409920]
ys = [124,433,853,1449]
在Excel中使用幂律可以得到一个很好的近似值:

Excel找到了表单的一个功能a(x^b).怎样才能确定a并b在C#中?我尝试使用Math.Net数字,但我没有看到任何适用于此形式的函数的方法.线性回归模块中的所有函数只能找到各种形式函数的线性系数,但似乎没有一个能够确定指数.
let inline (!>) (x:^a) : ^b = ((^a or ^b) : (static member op_Implicit : ^a -> ^b) x)
Run Code Online (Sandbox Code Playgroud)
我已经知道F#了一段时间,但我不知道如何解析这里的实现.什么是(^a or ^b)?之后的东西?请仔细阅读每个部分所代表的内容.
我正在调查一个NullReferenceException我无法在本地重现的问题,我需要排除Newtonsoft.Json.JsonConvert.DeserializeObject<T>潜在的 null 来源。当我使用一些无效输入在本地尝试时,它总是抛出异常并且从不返回 null。我的代码假设它不抛出异常,它返回一个非空对象。该文件没有说明这两种方式。
版本4.5.11是相关的。
我正在看这个代码示例,并偶然发现了这种语法:
import React, { Component } from 'react';
const PrivateRoute = ({component:Component, ...rest}) => (
//(...)
<Component {...props} />
// (...)
);
Run Code Online (Sandbox Code Playgroud)
我对这:Component部分感到困惑.这看起来像一个静态类型的注释,其行为类似于泛型,但这是Javascript所以它只能是一个对象,对吧?如果这是一个对象,这是否意味着该函数将默认的空Component对象分配给它自己的参数?如果是这样,它如何能够从调用者接收它,例如(根据示例):
<PrivateRoute path="/protected" component={Protected} />
Run Code Online (Sandbox Code Playgroud) 今天我注意到以下内容无法编译:
open System
type MyType() =
member this.Something() =
this.F(3)
this.F("boo")
// ^^^^^
// This expression was expected to have type 'int' but here has type 'string'
member private this.F<'T> (t:'T) =
// ^^
// This type parameter has been used in a way that constrains it to always be 'int'
// This code is less generic than required by its annotations because the explicit type variable 'T' could not be generalized. It was constrained to be 'int'.
Console.WriteLine (t.GetType()) …Run Code Online (Sandbox Code Playgroud) 根据规范第3.4节,这不编译:
let s: string | number;
s = false; // not a string or a number
Run Code Online (Sandbox Code Playgroud)
所以,从逻辑上讲,给定A,B和C类,我也希望这不会编译,但它确实:
let a: A | B;
a = new C();
a = "hi";
a = {}; // a can be anything!
Run Code Online (Sandbox Code Playgroud)
是否有一些解决方法可以在这里进行更严格的类型检查?此外,这是一个错误还是设计?如果是设计,我真的不明白这个设计选择.
F# 代码格式指南针对以下情况提供了有关 PascalCase 和 camelCase 使用的建议:
camelCase 为了
PascalCase 为了
它似乎没有说明如何处理模块中的公共绑定值(不是函数),例如
module MyModule =
let aValue = ""
Run Code Online (Sandbox Code Playgroud)
在F#的核心,有驼峰的一些例子:
Set.empty,List.empty,Unchecked.defaultOf
但我见过两者都在野外使用。
我有一个类似于此的函数A,它将函数B应用于目录中的每个文件.每个文件都有一定数量的"条目"; 函数B将当前的条目总数作为参数,并返回当前文件中找到的新条目数.
此外,我需要计算处理的文件数,并在每次处理文件时显示此计数.由于我的命令背景,我提出了2个可变变量和一个for循环.
let files = Directory.EnumerateFiles sourceDirectory
let mutable numEntries = 0
let mutable numFiles = Seq.length files
let mutable index = 0
for file in files do
printfn "done %d of %d" index numFiles
let numNewEntries = processFile file numEntries
numEntries <- numEntries + numNewEntries
index <- index + 1
Run Code Online (Sandbox Code Playgroud)
那么,有几个问题:
我做了以下投地double,并回long,故意:
var adjustedValue = (long)(double)dateTime.Ticks;
Run Code Online (Sandbox Code Playgroud)
(dateTimea System.DateTime和Ticksa 在哪里long).然而Resharper告诉我,演员double是"多余的",这让我想知道它是否可以被编译器优化掉.
源视频在mp4容器中是H264,我正在尝试将其拆分为单独的编码帧.我尝试使用以下命令行:
ffmpeg -i "input.mp4" -f image2 "%d.h264"
Run Code Online (Sandbox Code Playgroud)
但是这会创建扩展名为"h264"的jpegs,而不是实际的H.264帧.