Ant中的Groovy脚本:使用脚本任务还是常规任务?(Groovy scripts in Ant: Use script task or groovy task?)
如果要在Ant中运行Groovy脚本,可以使用如下脚本任务 :
<script language="groovy"> //foo </script>
..或那样的常规任务 :
<groovy> //foo </groovy>
两种方式都需要下载Groovy库。 我找到了一个看起来很有希望的Ant配置,在这个答案中自动执行此操作: 使用ant或maven执行我的groovy脚本
现在我的问题 :
两个Ant任务中的哪一个用于运行Groovy脚本?
script
还是groovy
?另外,如果Ant中包含一个支持groovy的脚本任务,那么“附加”groovy任务的目的是什么?
另外我想引用我在这里找到的博客文章: http : //jbetancourt.blogspot.co.at/2012/03/run-groovy-from-ants-script-task.html
当然,为什么在'groovy'任务可用时你会使用'脚本'任务? 你不会。
有人同意这篇文章的作者吗? 如果是这样 - 你能解释它背后的想法吗?
If you want to run a Groovy script in Ant, you can either use the script task like this: ..
<script language="groovy"> //foo </script>
..or the groovy task like that:
<groovy> //foo </groovy>
Both ways require the Groovy libraries to be downloaded. I found a promising looking Ant config that does this automatically in this answer: Execute my groovy script with ant or maven
Now for my question:
Which of the two Ant tasks is meant to be used for running Groovy scripts?
script
orgroovy
?Also, what is the purpose of the "additional" groovy task, if there's a script task included in Ant that supports groovy?
Also I'd like to quote from a blog post I found here: http://jbetancourt.blogspot.co.at/2012/03/run-groovy-from-ants-script-task.html
Of course, why would you use the 'script' task when the 'groovy' task is available? You wouldn't.
Does anyone agree with the author of this post? If so - could you explain the idea behind it?
原文:https://stackoverflow.com/questions/16699949
最满意答案
可以在F#中执行此操作,但它不是惯用的:
let inline sum a b = (^T : (member Property : int) a) + (^U : (member Property : int) b)
一般来说,.NET泛型与C ++模板非常不同,因此在尝试在F#中模拟C ++之前,可能首先需要了解它们之间的差异。 一般的.NET哲学是操作由名义类型而不是结构类型定义。 在您的示例中,您可以定义一个公开
Property
属性的接口,您的两个类将实现该属性,然后您的sum
函数将接受该接口的实例。有关F#泛型的更多信息,请参见http://msdn.microsoft.com/en-us/library/dd233215.aspx ; 有关.NET泛型与C ++模板的简要比较,请参阅http://blogs.msdn.com/b/branbray/archive/2003/11/19/51023.aspx (或者当您使用Google“.NET时出现的任何内容)泛型C ++模板“)。
It is possible to do this in F#, but it isn't idiomatic:
let inline sum a b = (^T : (member Property : int) a) + (^U : (member Property : int) b)
In general, .NET generics are very different from C++ templates, so it's probably worth learning about their differences first before trying to emulate C++ in F#. The general .NET philosophy is that operations are defined by nominal types rather than structural types. In your example you could define an interface exposing a
Property
property, which your two classes implement, and then yoursum
function would take instances of that interface.See http://msdn.microsoft.com/en-us/library/dd233215.aspx for more information on F# generics; for a brief comparison of .NET generics versus C++ templates see http://blogs.msdn.com/b/branbray/archive/2003/11/19/51023.aspx (or really anything that comes up when you Google ".NET generics C++ templates").
相关问答
更多-
你的方法对我来说似乎是正确的 你的代码不能编译的原因是因为F#类型推断是推断类型变量'T的静态约束(编译时),它与类型定义相同。 类型定义的泛型参数不能静态解析(没有“帽子”类型),但是没有什么能阻止你定义一个使用这些编译时间约束的函数或成员。 只需在静态成员(+)定义中将您的类型变量'T 'U更改为'U 。 尽管如此,你仍然可以创建一个不支持(+)的类型的TimeSeries实例(即: TimeSeries
),但你将无法使用(+)作为这些实例,无论如何,如果你这样做在编译时会得到一个很好的错误 ... -
你想要“typedefof” printfn "%s" (typedefof
- >).Name
You want "typedefof" printfn "%s" (typedefof
- >).Name
-
您要求的功能是协变类型。 协方差允许返回类型,它是一个子类型,而不是泛型类型参数精确定义的类型(不仅仅适用于接口,而不适用于具体类型)。 这允许您将IEnumerable
:?> IEnumerable -
约束不是方法签名的一部分(根据ECMA 335,I.8.6.1.5方法签名 ),这意味着在CIL中,您不能有两种签名仅在约束条件上有所不同的方法。 为了在CIL中编码这样的签名,需要使用可选或必需的修饰符,但这不是很简单,今天F#不这样做。 Constraints are not part of method signature (per ECMA 335, I.8.6.1.5 Method signatures) meaning that in CIL you cannot have two method ...
-
F#泛型约束(F# Generics Constraints)[2022-04-06]
我不知道为什么我的代码显示错误消息,但我找到了解决方法,我在GitHub项目上提交。 您可以检查此文件上的差异,因为它比描述它更容易阅读。 https://github.com/Ar3sDevelopment/Caelan.Frameworks.BIZ/commit/22898671635b4667c8741853af9cc86910e1ff5a#diff-d5779b1053a390520d2a4a0c643f3d68 该链接包含解决问题的差异,但我将在下一行解释。 我用一种解决方法解决了它,我不知道它为 ... -
冒着显而易见的风险,一个足够好的解决方案可能是拥有一个mapTuple ,它需要两个函数而不是一个函数: let mapTuple fa fb (a, b) = (fa a, fb b) 如果你的原始f是通用的,那么将它作为fa和fb传递给你,你将要找到的函数有两个具体实例。 最糟糕的情况是,当a和b属于同一类型时,只需要传递相同的函数两次。 At the risk of stating the obvious, a good enough solution might be to have a mapT ...
-
它说需要/两次因为类型不是必需的,所以你的功能将比你期望的更通用。 在设计通用数学库时,必须做出一些决定。 你不能只是在没有类型注释所有内容或限制数学运算符的情况下继续前进,类型推断将无法提出类型。 问题是F#算术运算符不受限制,它们有一个'开放'签名: 'a->'b->'c所以你要么限制它们,要么你必须完整的类型注释你的所有功能,因为如果你不' t F#将无法知道应该采取哪种过载。 如果你问我,我将采用第一种方法(也就是Haskell方法),它在开始时有点复杂,但是一旦你完成所有设置,实现新的泛型类型及其 ...
-
我刚刚创建了一个全新的解决方案,它工作得很好......我仍然不知道问题是什么...... I just created a brand new solution and it worked perfectly fine... I still don't know what the problem was though...
-
我建议你放弃单身人士的想法,而是使用实例成员,完全避免这个问题。 单身人士开始时是一个坏主意。 一种方法是建立一个带有工厂的模块,可能会被懒惰地评估(虽然我不认为这是你方案中的一个问题,但创建它们并不昂贵)。 然后,您可以直接使用该模块,或者可以通过您要创建的类型上的静态成员重新公开它,例如 type CollegeSizeFactory () = inherit UnionFactory
(CollegeSize.all) module F ... -
可以在F#中执行此操作,但它不是惯用的: let inline sum a b = (^T : (member Property : int) a) + (^U : (member Property : int) b) 一般来说,.NET泛型与C ++模板非常不同,因此在尝试在F#中模拟C ++之前,可能首先需要了解它们之间的差异。 一般的.NET哲学是操作由名义类型而不是结构类型定义。 在您的示例中,您可以定义一个公开Property属性的接口,您的两个类将实现该属性,然后您的sum函数将接受该接口的实 ...