Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lightweight syntax and nested records

This program:

type A = { a : int }
type B = { b : A }

//34567890
let r = {
  b = {      // line 6
    a = 2    // line 7 
  } 
}

Produces under mono/fsharpc this warning twice:

/Users/debois/git/dcr/foo.fs(7,5): warning FS0058: Possible incorrect indentation: this token is offside of context started at position (6:7). Try indenting this token further or using standard formatting conventions.

  1. Why does this warning occur at all? The f#-spec p. 228 makes me think the token 'a' following '{' sets a new offside line, in which case there should be no problem?

  2. Why does it occur twice?

Thanks,

Søren

Full output:

dcr > fsharpc foo.fs
F# Compiler for F# 3.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License

/Users/debois/git/dcr/foo.fs(7,5): warning FS0058: Possible incorrect indentation: this token is offside of context started at position (6:7). Try indenting this token further or using standard formatting conventions.

/Users/debois/git/dcr/foo.fs(7,5): warning FS0058: Possible incorrect indentation: this token is offside of context started at position (6:7). Try indenting this token further or using standard formatting conventions.
dcr > 
like image 478
Søren Debois Avatar asked Mar 08 '14 07:03

Søren Debois


1 Answers

reformat your code as

type A = { a : int }
type B = { b : A }

//34567890
let r = { b = { a = 2 } }

or

let r =
    {
       b = { a = 2 } 
    }

i.e. the { is the left-most token.

EDIT: One off-site line starts with the { therefore you need to indent at least as much as the { the line break after is not mandatory. And the second warning is because of the same reason.

like image 106
Daniel Fabian Avatar answered Oct 17 '22 09:10

Daniel Fabian