Header menu logo Fabulous.AST

Delegates

Contents

#r "../../src/Fabulous.AST/bin/Release/netstandard2.1/publish/Fantomas.Core.dll"
#r "../../src/Fabulous.AST/bin/Release/netstandard2.1/publish/Fabulous.AST.dll"
#r "../../src/Fabulous.AST/bin/Release/netstandard2.1/publish/Fantomas.FCS.dll"

open Fabulous.AST
open type Fabulous.AST.Ast

Overview

A delegate names a function signature. Delegate takes the type name, the parameter type(s), and the return type.

Basic Usage

A single parameter and a return type:

Oak() { AnonymousModule() { Delegate("IntTransform", Int(), Int()) } }
|> Gen.mkOak
|> Gen.run
|> printfn "%s"

// produces the following code:
type IntTransform = delegate of int -> int

Tupled and Named Parameters

Pass a list of types (or type names) for several parameters, and use SignatureParameter to name them:

Oak() {
    AnonymousModule() {
        Delegate("BinaryOp", [ "int"; "int" ], "int")

        Delegate("NamedArgs", Tuple([ SignatureParameter("a", Int()); SignatureParameter("b", Int()) ]), Int())

        Delegate("Curried", [ Paren(Tuple([ Int(); Int() ])); Paren(Tuple([ Int(); Int() ])) ], Int())
    }
}
|> Gen.mkOak
|> Gen.run
|> printfn "%s"

// produces the following code:
type BinaryOp = delegate of int * int -> int
type NamedArgs = delegate of a: int * b: int -> int
type Curried = delegate of (int * int) * (int * int) -> int

Access Modifiers

Set accessibility with toPrivate, toInternal, or toPublic:

Oak() { AnonymousModule() { Delegate("InternalOp", [ "int"; "int" ], "int") |> _.toInternal() } }
|> Gen.mkOak
|> Gen.run
|> printfn "%s"

// produces the following code:
type internal InternalOp = delegate of int * int -> int
namespace Fabulous
namespace Fabulous.AST
type Ast = class end
Multiple items
static member Ast.Oak: unit -> CollectionBuilder<Fantomas.Core.SyntaxOak.Oak,'marker>

--------------------
module Oak from Fabulous.AST
static member Ast.AnonymousModule: unit -> CollectionBuilder<Fantomas.Core.SyntaxOak.ModuleOrNamespaceNode,Fantomas.Core.SyntaxOak.ModuleDecl>
Multiple items
static member Ast.Delegate: name: string * parameter: string * returnType: string -> WidgetBuilder<Fantomas.Core.SyntaxOak.TypeDefn>
static member Ast.Delegate: name: string * parameter: string * returnType: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> -> WidgetBuilder<Fantomas.Core.SyntaxOak.TypeDefn>
static member Ast.Delegate: name: string * parameter: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> * returnType: string -> WidgetBuilder<Fantomas.Core.SyntaxOak.TypeDefn>
static member Ast.Delegate: name: string * parameter: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> * returnType: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> -> WidgetBuilder<Fantomas.Core.SyntaxOak.TypeDefn>
static member Ast.Delegate: name: string * parameters: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> seq * returnType: string -> WidgetBuilder<Fantomas.Core.SyntaxOak.TypeDefn>
static member Ast.Delegate: name: string * parameters: string seq * returnType: string -> WidgetBuilder<Fantomas.Core.SyntaxOak.TypeDefn>
static member Ast.Delegate: name: string * parameters: string seq * returnType: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> -> WidgetBuilder<Fantomas.Core.SyntaxOak.TypeDefn>
static member Ast.Delegate: name: string * parameters: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> seq * returnType: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> -> WidgetBuilder<Fantomas.Core.SyntaxOak.TypeDefn>

--------------------
module Delegate from Fabulous.AST
static member Ast.Int: value: int -> WidgetBuilder<Fantomas.Core.SyntaxOak.Constant>
static member Ast.Int: unit -> WidgetBuilder<Fantomas.Core.SyntaxOak.Type>
type Gen = static member mkOak: root: WidgetBuilder<'node> -> 'node static member parse: source: string -> string + 1 overload static member run: oak: Oak -> string + 1 overload
<summary> Renders a widget tree to F# source and verifies the result. <c>mkOak</c> turns the root widget into a Fantomas node (recursively building its children), <c>run</c> formats that node to source (optionally with a config), and <c>parse</c> round-trips the source back through the parser to confirm it is syntactically valid. Designed for pipeline use, e.g. <c>widget |&gt; Gen.parse</c> or <c>widget |&gt; Gen.mkOak |&gt; Gen.run |&gt; Gen.parse</c>. </summary>
static member Gen.mkOak: root: WidgetBuilder<'node> -> 'node
static member Gen.run: oak: Fantomas.Core.SyntaxOak.Oak -> string
static member Gen.run: oak: Fantomas.Core.SyntaxOak.Oak * config: Fantomas.Core.FormatConfig -> string
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Multiple items
static member Ast.Tuple: items: string seq * exponent: string -> WidgetBuilder<Fantomas.Core.SyntaxOak.Type>
static member Ast.Tuple: items: string seq -> WidgetBuilder<Fantomas.Core.SyntaxOak.Type>
static member Ast.Tuple: items: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> seq * exponent: string -> WidgetBuilder<Fantomas.Core.SyntaxOak.Type>
static member Ast.Tuple: items: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> seq -> WidgetBuilder<Fantomas.Core.SyntaxOak.Type>

--------------------
module Tuple from Fabulous.AST
Multiple items
static member Ast.SignatureParameter: identifier: string * tp: string -> WidgetBuilder<Fantomas.Core.SyntaxOak.Type>
static member Ast.SignatureParameter: tp: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> -> WidgetBuilder<Fantomas.Core.SyntaxOak.Type>
static member Ast.SignatureParameter: identifier: string * tp: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> -> WidgetBuilder<Fantomas.Core.SyntaxOak.Type>

--------------------
module SignatureParameter from Fabulous.AST
static member Ast.Paren: value: string -> WidgetBuilder<Fantomas.Core.SyntaxOak.Type>
static member Ast.Paren: value: WidgetBuilder<Fantomas.Core.SyntaxOak.Type> -> WidgetBuilder<Fantomas.Core.SyntaxOak.Type>

Type something to start searching.