f#分形-一个我不知道的错误。

时间:2022-02-27 00:16:32

I'm trying to make an example I've found on the net work. It's a 3D fractal in F#. Here it is: http://tomasp.net/blog/infinite-cheese.aspx. The source code is available for download at the end of the article. The article and the sample were written in 2007, so I think the code is just slightly obsolete. There is one block of code that causes error and the code won't compile:

我想举一个我在网上找到的例子。它是f#中的一个三维分形。这是:http://tomasp.net/blog/infinite-cheese.aspx。源代码可以在文章的最后下载。文章和示例是在2007年编写的,所以我认为代码有点过时。有一个代码块会导致错误,代码无法编译:

// Returns a cube with filtered sides
let private get_cube(incl_sides) =
    [ for (side,trigs) in cube
        when Set.mem side incl_sides
        ->> trigs ]

The when keyword is underlined, and the error message goes as follows:

当关键字下划线时,错误信息如下:

Unexpected keyword 'when' in expression. Expected '->' or other token.

在表达式中出现意外的关键字“when”。预期“->”或其他令牌。

I can't figure out what's wrong with this. In an attempt to understand the code better, I searched the langauge specs. As far as I know, there is nothing about the Set.mem function or the ->> operator. Do you have any idea what could be wrong?

我不知道这有什么不对。为了更好地理解代码,我搜索了langauge规范。据我所知,没有关于Set.mem函数或>>操作符。你知道有什么不对劲吗?

2 个解决方案

#1


1  

Try

试一试

[for (side, trigs) in cube do
    if Set.contains side incl_sides then
        yield! trigs]

The language has undergone a lot of changes since that code was written. In particular, the ->> operator has been replaced by yield!, Set.mem has been renamed to the more descriptive Set.contains, and comprehensions now use if ... then instead of when.

自编写代码以来,该语言经历了很多变化。特别是->>算子被yield所取代!, Set.mem已被重命名为更具描述性的Set.contains,现在如果…然后,而不是时候。

#2


1  

Yes, the version of the source code that is linked from the blog post is a bit old. You can find the latest (updated) version in the F# samples project on CodePlex. I think there may be some other changes, so it is best to get the version from CodePlex. (It includes FractalSimple.fs which is simpler version and Fractal.fs which also removes cube sides that are not visible).

是的,从博客文章中链接的源代码版本有点旧了。您可以在CodePlex上的f#示例项目中找到最新的(更新的)版本。我认为可能还有其他的变化,所以最好从CodePlex上下载这个版本。(它包括FractalSimple。它是更简单的版本和分形。它还去除不可见的立方体边)。

The project contains standard Visual Studio 2008/2010 .fsproj project. The original version on the blog was written using F# CTP (from VS 2005 times) which had a completely different Visual Studio integration and used an obsolete .fsharpp project format (before MSBUILD format existed).

该项目包含标准Visual Studio 2008/2010 .fsproj项目。博客上的原始版本是使用f# CTP(来自VS 2005 times)编写的,它具有完全不同的Visual Studio集成,并使用了过时的.fsharpp项目格式(在MSBUILD格式存在之前)。

The when and ->> constructs have been used as a lightweight syntax for writing queries, but are now deprecated, to keep the syntax inside comprehensions consistent with the rest of the language. As kvb points out, you can use ordinary if .. then and the only non-standard thing is yield!, which means return all elements of the given sequence.

>和->结构已经被用作编写查询的轻量级语法,但现在已经被弃用,以保持内部的语法理解与语言的其他部分一致。正如kvb指出的,如果…那么,唯一不标准的就是收益率!,即返回给定序列的所有元素。

#1


1  

Try

试一试

[for (side, trigs) in cube do
    if Set.contains side incl_sides then
        yield! trigs]

The language has undergone a lot of changes since that code was written. In particular, the ->> operator has been replaced by yield!, Set.mem has been renamed to the more descriptive Set.contains, and comprehensions now use if ... then instead of when.

自编写代码以来,该语言经历了很多变化。特别是->>算子被yield所取代!, Set.mem已被重命名为更具描述性的Set.contains,现在如果…然后,而不是时候。

#2


1  

Yes, the version of the source code that is linked from the blog post is a bit old. You can find the latest (updated) version in the F# samples project on CodePlex. I think there may be some other changes, so it is best to get the version from CodePlex. (It includes FractalSimple.fs which is simpler version and Fractal.fs which also removes cube sides that are not visible).

是的,从博客文章中链接的源代码版本有点旧了。您可以在CodePlex上的f#示例项目中找到最新的(更新的)版本。我认为可能还有其他的变化,所以最好从CodePlex上下载这个版本。(它包括FractalSimple。它是更简单的版本和分形。它还去除不可见的立方体边)。

The project contains standard Visual Studio 2008/2010 .fsproj project. The original version on the blog was written using F# CTP (from VS 2005 times) which had a completely different Visual Studio integration and used an obsolete .fsharpp project format (before MSBUILD format existed).

该项目包含标准Visual Studio 2008/2010 .fsproj项目。博客上的原始版本是使用f# CTP(来自VS 2005 times)编写的,它具有完全不同的Visual Studio集成,并使用了过时的.fsharpp项目格式(在MSBUILD格式存在之前)。

The when and ->> constructs have been used as a lightweight syntax for writing queries, but are now deprecated, to keep the syntax inside comprehensions consistent with the rest of the language. As kvb points out, you can use ordinary if .. then and the only non-standard thing is yield!, which means return all elements of the given sequence.

>和->结构已经被用作编写查询的轻量级语法,但现在已经被弃用,以保持内部的语法理解与语言的其他部分一致。正如kvb指出的,如果…那么,唯一不标准的就是收益率!,即返回给定序列的所有元素。