gpt4 book ai didi

F# 注释错误

转载 作者:行者123 更新时间:2023-12-04 10:04:27 25 4
gpt4 key购买 nike

我在自学 F# 我通常是一名 C# 程序员。

我正在尝试使用 (**)在我阅读章节时为自己做笔记,但我从评论本身中得到了一个错误。

module Characters

let vowels = ['a', 'e', 'i', 'o', 'u']

printfn "Hex u0061 = '%c'" '\u0061'

(* <------------Error is here, is 'End of file in string embedded in comment begun at or before here'
Character Escape Sequences

Character Meaning
-------------------------------
\' Single Quote
\" Double Quote
\\ Backslash
\b Backspace
\n Newline
\r Carriage Return
\t Horisontal Tab
*)

这是否将评论视为字符串意味着我必须转义我的评论?

最佳答案

F#琐事时间!这是设计使然。 Block comments can be nested, and strings within a block comment are tokenized like regular strings .在这种情况下,有效的字 rune 字算作“字符串”。

所以这些是有效的块注释:

(* "embedded string, this --> *) doesn't close the comment" *)
(* (* nested *) comment *)
(* quote considered to be in char literal '"' is ok *)

但这些都不是
(* "this string is not closed *)
(* " this quote --> \" is escaped inside a string *)

好像这还不够疯狂,还有 special treatment for operators which begin with * (*)等通常被认为是块注释的开始或结束。
(* I can talk about the operator (*) without ending my comment *)

AFAIK,这些都是从 ML 继承的(嵌套注释肯定是,不确定字符串)。

因此,出于您的目的,您可能想要执行以下操作:
(*  Character       Meaning
-------------------------------
" \' " Single Quote
" \" " Double Quote

or

'\'' Single Quote
'"' Double Quote
*)

关于F# 注释错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18132557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com