0
votes

I'm trying to make a recursive function in F# and am really new in F# and functional programming so this is probably basic stuff.

let rec groupTheResults (htmlNodes : seq<HtmlNode>, resultList: List<HtmlNodeGroup>) :List<HtmlNodeGroup> =
    if Seq.length htmlNodes > 0 then
        let listThing = Seq.take 2 htmlNodes
        []
    else []

If I remove let listThing = Seq.take 2 htmlNodes then the compiler is all happy. Am I doing something illegal or what?

1
What error do you get when you leave the let line in? - JaredPar
For me with some dummy definitions this code compiles fine. - John Palmer
error FS0010: Unexpected keyword 'else' in expression. Expected 'in' or other token. - eble
Is it possible you are mixing tabs and spaces here in a way that's causing the F# compiler to believe that [] is aligned with the if instead of with the let - JaredPar
You get that error with #indent "off" - possibly it is hanging around from somewhere - John Palmer

1 Answers

0
votes

From some discussion in the comments, that error is generated using

#indent "off"

which disables F#'s whitespace sensitivity. As a result, an in expected after the let ... line.

You need to reload your fsi session (rightclick -> reset interactive session) to clear it. Typing

#indent "on" 

might also work