Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# Comment error

Tags:

f#

I am teaching myself F# I am normally a C# programmer.

I am trying to use the (**) to make notes for myself as I go through the chapters but I am getting an error from the comment itself.

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
*)

Is this treating the comment like a string meaning I have to escape my comment?

like image 683
Cubicle.Jockey Avatar asked Aug 08 '13 17:08

Cubicle.Jockey


Video Answer


2 Answers

F# trivia time! This is by design. Block comments can be nested, and strings within a block comment are tokenized like regular strings. Valid char literals count as "strings" in this case.

So these are valid block comments:

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

But these are not

(* "this string is not closed *)
(* " this quote --> \" is escaped inside a string *)

And as if that wasn't crazy enough, there is special treatment for operators which begin with * since (*) and the like would normally be considered the start or end of a block comment.

(* I can talk about the operator (*) without ending my comment *)

AFAIK, these are all inherited from ML (nested comments definitely are, not sure about strings).

So for your purposes, you might want to do something like this:

(*  Character       Meaning
    -------------------------------
    " \' "          Single Quote
    " \" "          Double Quote

    or

    '\''            Single Quote
    '"'             Double Quote
*)
like image 125
latkin Avatar answered Sep 20 '22 01:09

latkin


It appears that the "Double Quote" line is the problem. If I remove that line, the error goes away. This looks like a bug in the parser, since the problem does not occur if I prefix each line with // instead of doing a block-comment. I'd suggest you send this to [email protected] - if it's not already fixed for Visual Studio 2013, maybe it's not too late.

Completely unrelated: your vowels list contains a single element that is a 5-part tuple. If you want it to be a list of characters instead of a list containing one 5-part tuple, use semicolons instead of commas.

like image 30
Joel Mueller Avatar answered Sep 19 '22 01:09

Joel Mueller