Hi Christopher,
the #light indentation requires that a code that belongs to the same block is indented to the same position. In your case the patterns in the pattern matching should start at the same location, so you can write:

1
2
3
4
5
6
 
#light
let rec conactStringList =
    function 
        head :: tail -> head + conactStringList tail
      | [] -> ""

It is also possible to place the function keyword at the same line as '='. The pipe symbol ('|') introduces every pattern (in the pattern matching), but it is optional for the first pattern (after the function keyword). I usually prefer to include it, but that depends on your personal preference :-).
I would probably write:

1
2
3
4
5
 
#light
let rec conactStringList = function 
  | head :: tail -> head + conactStringList tail
  | [] -> ""
By on 8/19/2007 8:10 AM ()

Ok, so to make sure I understand correctly, the reason for the non-compiling code was that the first bracket in | [] -> "" didn't line up with the h in head from the line above. That's the tidbit of information I was missing.

Is #light documented somewhere? I haven't made it all the way through the "F# Manual" documentation yet.

Thanks! :)

Christopher C. Bernholt

By on 8/19/2007 9:10 AM ()

Hi,
the code from the book is correct, because "head::tail" patten starts at the same location as "[]" pattern - if you omit the "|" symbol in the first pattern than the indentation can be done in this way. In the code with one additional space the "[]" pattern is indented further than "head::tail", which causes the problem.

#light is documented in the F# manual - here is a direct link: [link:research.microsoft.com]

By on 8/19/2007 10:41 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper