F# representer 的规范化

概述 F# representer 对提交的解答所做的各项规范化


F# representer 会执行以下规范化:

移除注释

所有注释都会被移除。

之前

module Fake

(* Block comment
   on multiple lines *)

let message = "Hi" (* Block comment after code *)

// Double-slash comment on single line
let reply = "Yo" // Double-slash comment after code

/// <summary>This function adds two numbers</summary>
/// <param name="x">The first number</param>
/// <param name="y">The second number</param>
/// <returns>The first number added to the second number</param>
let add x y = x + y

之后

module Fake

let message = "Hi"

let reply = "Yo"

let add x y = x + y

移除导入声明

所有导入声明都会被移除。

之前

module Fake

open System
open System.IO

let message = "Hi"

之后

module Fake

let message = "Hi"

格式化代码

代码使用 fantomas 库 进行格式化。 它会按照 F# 风格指南来格式化代码。 fantomas 应用的全部转换列表可以在这里找到。

之前

module Fake

let  add ( birthDate  :  DateTime)  =
    birthDate.Add (    2.0)

type Volume =
| Liter of float
| USPint of float
| ImperialPint of float

之后

module Fake

let add (birthDate: DateTime) =
    birthDate.Add(2.0)

type Volume =
    | Liter of float
    | USPint of float
    | ImperialPint of float

规范化标识符

标识符会被规范化为占位符值。

之前

module Fake

let foo x = x + 1

之后

module PLACEHOLDER_1

let PLACEHOLDER_3 PLACEHOLDER_2 = PLACEHOLDER_2 + 1