F# Computation Expressions de-sugaring tool

220 Views Asked by At

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

1

There are 1 best solutions below

0
Koenig Lear On

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 

Related Questions in F#