fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

`let rec` with `and` on the same line error without `#light "off"`

Open kryptine opened this issue 4 years ago • 1 comments

The following occurs on the latest .NET SDK 6.0.1.

#nowarn "62"
#light "off"
namespace Library

module Compute = begin
    type BinaryExpression<'f,'t,'a> = BinConst of 'a | BinVar of 't | BinApp of 'f * BinaryExpression<'f,'t,'a> * BinaryExpression<'f,'t,'a>
    type AtMostBinaryExpression<'d,'e,'j,'k> = AMBConst of 'k | AMBVar of 'j | AMBAppU of 'd * AtMostBinaryExpression<'d,'e,'j,'k> | AMBAppB of 'e * AtMostBinaryExpression<'d,'e,'j,'k> * AtMostBinaryExpression<'d,'e,'j,'k>
    type TernaryExpression<'m,'w,'r>= TerConst of 'r | TerVar of 'w | TerApp of 'm * TernaryExpression<'m,'w,'r> * TernaryExpression<'m,'w,'r> * TernaryExpression<'m,'w,'r>
    type AtMostTernaryExpression<'p,'q,'r,'z,'l> = AMTConst of 'l | AMTVar of 'z | AMTAppU of 'p * AtMostTernaryExpression<'p,'q,'r,'z,'l> | AMTAppB of 'q * AtMostTernaryExpression<'p,'q,'r,'z,'l> * AtMostTernaryExpression<'p,'q,'r,'z,'l> | AMTAppT of 'r * AtMostTernaryExpression<'p,'q,'r,'z,'l> * AtMostTernaryExpression<'p,'q,'r,'z,'l> * AtMostTernaryExpression<'p,'q,'r,'z,'l>
    let rec liftBinaryExpression(exp: BinaryExpression<'a,'r,'g>) = match exp with BinConst t -> AMBConst t | BinVar u -> AMBVar u | BinApp(i,o,p) -> AMBAppB(i,liftBinaryExpression o,liftBinaryExpression p) and liftTernaryExpression(y: TernaryExpression<'l,'k,'m>) = match y with TerConst a -> AMTConst a | TerVar k -> AMTVar k | TerApp(s,g,u,r) -> AMTAppT(s,liftTernaryExpression g,liftTernaryExpression u,liftTernaryExpression r);;

end
  1. In the command line type dotnet new classlib -lang F# --framework netstandard2.0
  2. Replace src/Library/Library.fs with the code above.
  3. Remove #light "off" from the code.
  4. Read the error message Unexpected keyword 'and' in expression. Expected incomplete structured construct at or before this point or other token.

kryptine avatar Jan 15 '22 23:01 kryptine

This is not a regression, at least it was in F# 5.0. Please just generate the code to write the let rec on separate lines.

Smaller repro:

namespace Library

module Compute = 
    let rec f x = 1 and g x = 2 

Workaround:

namespace Library

module Compute = 
    let rec f x = 1
    and g x = 2 

dsyme avatar Jan 21 '22 16:01 dsyme