小编por*_*ges的帖子

在F#中实现Indexer

我试图将此C#代码转换为F#:

double[,] matrix;

public Matrix(int rows, int cols)
    {
        this.matrix = new double[rows, cols];
    }

 public double this[int row, int col]
    {
        get
        {
            return this.matrix[row, col];
        }
        set
        {
            this.matrix[row, col] = value;
        }
    }
Run Code Online (Sandbox Code Playgroud)

基本上我最大的问题是在F#中创建索引器.网络上的任何地方我找不到任何可以应用的东西.我包括了该类的其他几个部分,以防将索引器合并到Matrix类型中并不明显.所以一个好的答案将包括如何从这里的三个部分中制作一个完整的类型,以及可能需要的任何其他东西.另外,我知道F#powerpack中的矩阵类型,但是我试图通过将我理解的C#项目转换为F#来学习F#.

提前致谢,

短发

f# indexer matrix

5
推荐指数
1
解决办法
1039
查看次数

在purescript中>> =意味着什么?

我正在读purescript维基,发现下面的章节这也解释了do在以下方面>>=.

什么>>=意思?

记谱法

do关键字为monadic表达式引入了简单的语法糖.

这是一个例子,使用monad作为Maybe类型:

 maybeSum :: Maybe Number -> Maybe Number -> Maybe Number 
 maybeSum a b = do   
     n <- a
     m <- b   
     let result = n + m   
     return result 
Run Code Online (Sandbox Code Playgroud)

maybeSum取两个值类型Maybe Number,如果两个数字都不是,则返回它们的总和 Nothing.

使用do表示法时,返回类型必须有Monad类型的相应实例.声明可以采用以下形式:

  • a <- x 不好意思 x >>= \a -> ...
  • xx >>= \_ -> ...如果这是最后一个陈述,那就是去掉或者只是x.
  • 一个让绑定let a = x.注意缺少in关键字.

例子maybeSum desugars to …

purescript

5
推荐指数
1
解决办法
497
查看次数

为什么Idris的Refl有时不会打字?

我正在阅读伊德里斯的书,我正在进行第一次证明练习.

通过练习证明same_lists,我能够像这样实现它,作为匹配Refl力量xy统一:

total same_lists : {xs : List a} -> {ys : List a} ->
    x = y -> xs = ys -> x :: xs = y :: ys
same_lists Refl Refl = Refl
Run Code Online (Sandbox Code Playgroud)

但是,当我试图以同样的方式证明其他东西时,我会遇到不匹配的问题.例如:

total allSame2 : (x, y : Nat) -> x = y -> S x = S y
allSame2 x y Refl = Refl
Run Code Online (Sandbox Code Playgroud)

编译器说:

Type mismatch between
   y = y (Type of Refl)
and
   x = …
Run Code Online (Sandbox Code Playgroud)

idris

3
推荐指数
1
解决办法
240
查看次数

F#中"==>"语法的含义

考虑F#中的以下代码

let rec ordered xs = 
    match xs with
      | [] | [_]        -> true
      | x1 :: x2 :: xs'  -> x1 <= x2 && ordered (x2 :: xs')
Run Code Online (Sandbox Code Playgroud)

然后

let rec insert x xs = 
    match xs with
    | []      -> [x]
    | y :: ys -> if x <= y then x :: y :: ys 
                 else           y :: insert x ys
Run Code Online (Sandbox Code Playgroud)

最后

let insertKeepsOrder (x : int) xs = ordered xs ==> ordered (insert x xs) …
Run Code Online (Sandbox Code Playgroud)

f# fscheck

2
推荐指数
1
解决办法
1339
查看次数

在类型中使用F#索引属性

我正在尝试将以下C#转换为F#:

    public class Matrix
    {
       double[,] matrix;

public int Cols
        {
            get
            {
                return this.matrix.GetUpperBound(1) + 1;
            }
        }

public int Rows
        {
            get
            {
                return this.matrix.GetUpperBound(0) + 1;
            }
        }

       public Matrix(double[,] sourceMatrix)
       {
        this.matrix = new double[sourceMatrix.GetUpperBound(0) + 1, sourceMatrix.GetUpperBound(1) + 1];
        for (int r = 0; r < this.Rows; r++)
        {
            for (int c = 0; c < this.Cols; c++)
            {
                this[r, c] = sourceMatrix[r, c];
            }
        }
       }

       public double this[int row, int col]
       {
         get …
Run Code Online (Sandbox Code Playgroud)

f# types indexed-properties

1
推荐指数
1
解决办法
708
查看次数

请求使用异步等待进行限制

我在我的应用程序中实现了一些请求限制.它基于使用MemoryCache和根据限制到期的项目.基本上我尝试检索一个缓存项目,如果它不在那里我继续发出请求,如果是他们我检查最后一个请求和锻炼下一个可用时间我可以提出请求.我的问题在于我必须等待提出请求.

//This is a shortened version of what im doing, but the includes the required code

public void ThrottleRequest(string webservice)
{
    if (cache.TryGet(webservice))
    {
          var timeToWait = GetTimeToWaitFromSomewhere(); 
          Wait(timeToWait);
    }
}

public async void Wait(TimeSpan timeToWait)
{
     await Task.Delay(timeToWait); //This doesnt work
     Thread.Sleep(timeToWait); //This works
}
Run Code Online (Sandbox Code Playgroud)

问题在于等待方法.如果我使用thread.sleep数字匹配并且请求被正确限制(即每秒1个请求)但我永远不想在生产环境中使用它.那么在这里异步等待的正确方法是什么?我滥用API还是什么?

c# asynchronous throttling

1
推荐指数
1
解决办法
1188
查看次数

VisualStudio 2017是否已经支持C++ 17代码合同?

有谁知道VS2017是否已经支持代码合同,如此处所见的C++ 17代码合同

当我尝试使用它们时

explicit IniHandler(std::string fileName) [[expects: fileName != nullptr]]
{
    this->fileName = fileName;
}
Run Code Online (Sandbox Code Playgroud)

它似乎不起作用.

我正在使用命令行选项/std:c++latest但仍然收到警告"标识符已被删除".

任何帮助很高兴:)

c++ assert contract c++17

0
推荐指数
1
解决办法
759
查看次数