hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

Indentation errors with light syntax under "module"

Last post 02-08-2009, 10:26 by Stringer. 3 replies.
Sort Posts: Previous Next
  •  02-03-2009, 13:22 8852

    Indentation errors with light syntax under "module"

    Everything below uses the #light syntax, with indentation as shown.

    The following code is fine:

    module test
        let x = 1.0  // this is OK


    The following gets an error on the last line "error in the return expression for this 'let'.  Possible incorrect indentation."

    module test
        let x = 1.0  // this is OK
        let y = 2.0  // indentation error if this is the last line


    The following gets an error on the last line, no error on the line above which is got the error above:

    module test
        let x = 1.0  // this is OK
        let y = 2.0  // indentation error if this is the last line
        let z = 3.0  // indentation error if this is the last line


    This one gets two errors:

    module test
        let x = 1.0  // indentation error
            let y = 2.0  // indentation error on this line too


    This, using no indentation, gets no errors.

    module test
    let x = 1.0  // OK
    let y = 2.0  // OK too



    Are there some rules for maintaining readability (i.e. using reasonable indentation) while avoiding these errors within modules?
  •  02-03-2009, 13:40 8854 in reply to 8852

    Re: Indentation errors with light syntax under "module"

    The language syntax here is a little nuts.

    If you put an '=' after 'module test' then your original first errors will go away (entities must be indented).  Then they become entities named e.g. 'Filename.test.x' - you are using the implicit module.  Without the '=', you get rid of the implicit module, and the entire file goes in a module named 'test' (e.g. 'test.x'), and you don't indent (apparently indenting makes it a 'do' expression, which is incomplete if it only contains 'let's as there's no body).

    I need to write a blog to explain all this in more detail.  I'll also file a bug for better error diagnostics.

  •  02-03-2009, 14:14 8855 in reply to 8854

    Re: Indentation errors with light syntax under "module"

    It works!  Thanks Brian.
  •  02-08-2009, 10:26 8920 in reply to 8852

    Re: Indentation errors with light syntax under "module"

    You can just insert an "open System" after your "module test" line. I find it's a good workaround too.
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems