1

A great help in dealing with F# computation expressions would be a way to look at how they are de-sugared during compilation. Is there a way to get the de-sugared version? For example:

  1. A tool like de-sugar ce.fs
  2. A compiler flag to print the output of the de-sugaring process like fsc --de-sugar-ces ce.fs
  3. A compiler service API like let desugared = compiler.DeSugar stringOrFilePath

Decompiling to C# is possible and helps as well, however what I am looking for is the F# de-sugared version, like in

enter image description here

Franco Tiveron
  • 2,364
  • 18
  • 34
  • You could compile and then decompile to C# using ILSpy – Fyodor Soikin Aug 29 '21 at 14:22
  • I use the online decompiler from C# or F# to C# https://sharplab.io/ but the resulting C# is quite verbose. Still it can be used to see what's behind the CE magic, like `Delay` and `Bind` functions – Romain Deneau Aug 30 '21 at 09:48

1 Answers1

0

I think the best way to understand them is to de-sugar them manually. The documentation gives some clear translations. Also be sure to read this excellent intro and examples by F# for fun and profit.

If you feel brave, you could implement a translator yoursself using F# compiler services.

You could walk over the expressions:

open FSharp.Compiler.SyntaxTree

| SynExpr.JoinIn 
| SynExpr.ImplicitZero
| SynExpr.YieldOrReturn 
| SynExpr.YieldOrReturnFrom
| SynExpr.LetOrUseBang 
| SynExpr.MatchBang 
| SynExpr.DoBang 
Koenig Lear
  • 2,366
  • 1
  • 14
  • 29