首页 \ 问答 \ F#Lambda签名(F# Lambda Signature)

F#Lambda签名(F# Lambda Signature)

我现在正在阅读克里斯史密斯的编程F#,当我遇到兰巴达斯时试图找出F#。 这是一个示例中的lambda

let generatePowerOfFunc base = (fun exponent -> base ** exponent);;

我得到它接收的东西并返回一个函数,但我没有得到的是这个函数的签名是val generatePowerOfFunc : float -> float -> float

它有三个花车而不是两个花车? 当有这种方法时

let powerOfTwo = generatePowerOfFunc 2.0;;

它只有2个浮动val powerOfTwo : (float -> float)

也许我没有得到整个类型的签名协议。 任何帮助将非常感激。 谢谢


I'm reading Programming F# by Chris Smith right now trying to figure out F# when i come across Lambadas. Here is a lambda from one of the examples

let generatePowerOfFunc base = (fun exponent -> base ** exponent);;

I get that it takes in something and returns a function, but what i don't get is the Signature of this function which is val generatePowerOfFunc : float -> float -> float

How does it have three floats instead of two? And when there's this method

let powerOfTwo = generatePowerOfFunc 2.0;;

It only has 2 floats val powerOfTwo : (float -> float)

Maybe Im not getting the whole type signature deal. Any help would be much appreciated. Thanks


原文:https://stackoverflow.com/questions/7611034
更新时间:2022-12-27 22:12

最满意答案

.eof()查看文件结束标志。 运行文件末尾设置该标志。 这是不可取的。

关于如何运作和最佳实践的博客文章可以在这里找到。

基本上,使用

std::string line;
while(getline(file, line)) { ... }

要么

while (file >> some_data) { ... }

因为它会在正确的时间发现错误和文件结束并采取相应的行动。


.eof() looks at the end of file flag. The flag is set after you run over the end of the file. This is not desirable.

A great blog post on how this works and best practice can be found here.

Basically, use

std::string line;
while(getline(file, line)) { ... }

or

while (file >> some_data) { ... }

as it will notice errors and the end of the file at the correct time and act accordingly.

相关问答

更多
  • eof 如何使用[2022-08-07]

    用 int a,b,c,d; while(scanf("%d%d%d%d",&a,&b,&c,&d)==4) { ... } 这样就可以了
  • EOF该怎么用?[2023-09-30]

    结束不了?是说执行程序后的那个命令行窗口关不了么? 你在行首按CTRL+Z,然后再回车就结束了…… 比如你输入一串abcdefg,这时窗口上是 abcdefg 然后回车换行,按CTRL+Z,这时窗口上是 ^Z 然后回车就结束了 这个按完CTRL+Z出来的^Z,必须要在行开头时按回车才可以关掉命令行窗口,其他任何位置都不行,按无数次也不行……
  • 没有EOF字符。 EOF的定义“不等于任何有效的字符代码”。 通常它是-1。 它在任何时候都不会写入文件。 在DOS中有一个历史的EOF字符值(CTRL + Z),但是这些日子已经过时了。 要回答Apoorv的后续问题:操作系统从不使用文件数据来确定文件长度(文件不以任何方式“空终止”)。 所以你不能欺骗操作系统。 也许旧的,愚蠢的程序不会在CTRL + Z字符后读取。 我不会认为任何Windows应用程序(甚至是记事本)都会这样做。 我的猜测是用一个空字符( \0 )来欺骗它们会更容易。 There is ...
  • 你非常接近,但可能受到你的帕斯卡背景的影响比理想。 你可能想要的更像是: #include using namespace std; // Bad idea, but I'll leave it for now. int main() { int k,sum = 0; // sum needs to be initialized. while (cin >> k) { sum += k; // `sum = sum + k;`, is ...
  • 正确的方法: string name; int number; int n = 0; while(in >> name >> number) { // The loop will only be entered if the name and number are correctly // read from the input stream. If either fail then the state of the // stream is set to ba ...
  • 其他人已经指出了你注意到的问题的细节。 然而,你应该意识到还有更多你还没有注意到的问题。 一个是相当明显的内存泄漏。 循环的每次迭代都会执行: Student * temp = new Student(); ,但你永远不会执行匹配的delete 。 C ++使内存管理比其他一些语言(如Java)简单得多,因为它需要你使用new每个对象。 在C ++中,你可以定义一个对象并使用它: Student temp; temp.input(studentFile); 这简化了代码并消除了内存泄漏 - 每次迭代结束 ...
  • .eof()查看文件结束标志。 在运行文件末尾后设置该标志。 这是不可取的。 关于如何运作和最佳实践的博客文章可以在这里找到。 基本上,使用 std::string line; while(getline(file, line)) { ... } 要么 while (file >> some_data) { ... } 因为它会在正确的时间发现错误和文件结束并采取相应的行动。 .eof() looks at the end of file flag. The flag is set after you ...
  • 在调用格式化提取操作之后,应始终检查是否设置了任何流的失败标志,在您的示例中,您正在检查response而不检查response是否已正确提取。 此外,您在提示输出中使用std::endl是没有意义的。 std::endl打印\n然后刷新缓冲区,但随后立即打印更多字符,以便刷新多余。 由于cin和cout (通常) 绑定 ,调用std::cin的输入函数将导致std::cout在任何情况下都被刷新,所以你也可以将\n放入你的提示字符串并保存在详细的额外<<运营商。 为什么不创建一个打印提示的提示函数,检索输 ...
  • 有一点可以帮助我实际检查fread()的返回状态。 内部函数执行此操作并返回-1表示错误,但main()的调用不检查状态。 在许多实现中, feof()在尝试读取文件末尾之前不会成立。 One thing which would help a lot is to actually check the return status of fread(). The inner function does that and returns -1 for error, but the call in main() t ...
  • “魔术值”-1定义为Traits::eof ,其中Traits是fin变量类型的traits_type typedef。 换句话说, decltype(fin)::traits_type::eof The "magic value" -1 is defined as Traits::eof, where Traits is the traits_type typedef of the type of your fin variable. In other word, decltype(fin)::trait ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)