1
votes

Given the following code:

namespace Backend

open System
open System.Linq
open Npgsql

module helpers =
    let rec second_elms lst =
        match lst with
        | [] -> []
        | (d,o)::xs -> o::(second_elms xs)

    let folder acc elm =
        let result_list,acc_to_substract = acc
        result_list::(elm-acc_to_substract),elm

type ChartManager() =

    static member ConvertOutputNumbersToDifferenceSegments(listOfOutputValuesForADay: list<DateTime*int>) =

        let secs = helpers.second_elms listOfOutputValuesForADay

        let trans = List.fold
            helpers.folder
            ([],snd(secs.First()))
            secs.Tail

        let sndDateTime = fst(listOfOutputValuesForADay.ElementAt(1))

        for each_output in fst(trans) do
            yield (sndDateTime,each_output)

It's giving me lots of errors, but I guess the majority are just cascading errors from the main one in the "trans" block, which says (highlighting the word helpers):

Unexpected identifier in binding. Expected incomplete structured construct at or before this point or other token.

What does this mean??

3

3 Answers

2
votes

To properly indent with light syntax

 let trans = 
       List.fold
           helpers.folder
           ([],snd(secs.First()))
           secs.Tail

or

 let trans = List.fold
                helpers.folder
                ([],snd(secs.First()))
                secs.Tail

If it's a single statement, to split on multiple lines you need to indent passed the start of the statement.

1
votes

When you do

let trans = 

the first thing after the equal sign = sets a new offside column. As long as you are writing only on or after the off-side column, you're defining the binding of trans. As soon as you write to the left of it, you're back outside trans, in this case defining the member ConvertOutputNumbersToDifferenceSegments.

However, when you go back outside, you often(*) have to go all the way back to some previous offside column. In this case the nearest one is set by the l in let trans ....

Altogether:

(* v ----------------- offside column set by 'let' *)
(*             v------ offside column set by '='.  *)

   let trans = List.fold
       helpers.folder               (* <-- Half way back. Error. *)
       ...

   let trans = List.fold 
               helpers.folder       (* <-- Binding 'trans'. *)
               ...

   let trans = List.fold
                  helpers.folder    (* <-- Also binding 'trans'. *)
                  ...

   let trans = List.fold            (* <-- Binding 'trans'. *)
   helpers.folder                   (* <-- Binding in member `Convert...` 
   ...                                     Yields type error in your case. *)

There's a brief guide to offside columns here.

(*) The exact rules vary by context.

0
votes

At a guess, you are confusing the indentation as helpers.folder is not indented as far as List.fold

I would change it to

    let trans = List.fold helpers.folder ([],snd(secs.First())) secs.Tail