1 people like it.

ML style module example

ML style module example

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
///
module Target = 
    
  /// There are three types of compilation
  /// targets. Eval for code compiled through
  /// the eval function, Global for code
  /// that is compiled in the global scope
  /// and Function for code inside function bodies
  type Mode
    = Eval
    | Global
    | Function

  /// Record that represents a compilation target
  /// which is a grouping of the following properties:
  /// 
  /// * Ast - The syntax tree to compile
  /// * Mode - The target mode (eval, global or function)
  /// * DelegateType - The target delegate signature we're targeting
  /// * ParameterTypes - The parameter types of the delegate signature's invoke method
  /// * Environment - The IronJS environment object we're compiling for
  type T = {
    Ast: Ast.Tree
    Mode: Mode
    DelegateType: Type option
    ParameterTypes: Type array
    Environment: Env
  }

  /// The amount of parameters for this target
  let parameterCount (t:T) =
    t.ParameterTypes.Length

  /// Extracts the parameter types from a delegate
  let getParameterTypes = function
    | None -> [||]
    | Some(delegateType:Type) -> 
      delegateType 
      $ FSharp.Reflection.getDelegateParameterTypes 
      $ FSharp.Array.skip 2

  /// Creates a new T record
  let create ast mode delegateType env =
    {
      Ast = ast
      Mode = mode
      Environment = env
      DelegateType = delegateType
      ParameterTypes = delegateType |> getParameterTypes
    }
    
  /// Creates a new T record with Eval mode
  let createEval ast env =
    env |> create ast Mode.Eval None

  /// Creates a new T record with Global mode
  let createGlobal ast env =
    env |> create ast Mode.Global None
type Mode =
  | Eval
  | Global
  | Function

Full name: Script.Target.Mode


 There are three types of compilation
 targets. Eval for code compiled through
 the eval function, Global for code
 that is compiled in the global scope
 and Function for code inside function bodies
union case Mode.Eval: Mode
union case Mode.Global: Mode
union case Mode.Function: Mode
type T =
  {Ast: obj;
   Mode: Mode;
   DelegateType: obj;
   ParameterTypes: obj;
   Environment: obj;}

Full name: Script.Target.T


 Record that represents a compilation target
 which is a grouping of the following properties:
 
 * Ast - The syntax tree to compile
 * Mode - The target mode (eval, global or function)
 * DelegateType - The target delegate signature we're targeting
 * ParameterTypes - The parameter types of the delegate signature's invoke method
 * Environment - The IronJS environment object we're compiling for
T.Ast: obj
Multiple items
T.Mode: Mode

--------------------
type Mode =
  | Eval
  | Global
  | Function

Full name: Script.Target.Mode


 There are three types of compilation
 targets. Eval for code compiled through
 the eval function, Global for code
 that is compiled in the global scope
 and Function for code inside function bodies
T.DelegateType: obj
type 'T option = Option<'T>

Full name: Microsoft.FSharp.Core.option<_>
T.ParameterTypes: obj
type 'T array = 'T []

Full name: Microsoft.FSharp.Core.array<_>
T.Environment: obj
val parameterCount : t:T -> 'a

Full name: Script.Target.parameterCount


 The amount of parameters for this target
val t : T
val getParameterTypes : _arg1:obj option -> obj []

Full name: Script.Target.getParameterTypes


 Extracts the parameter types from a delegate
union case Option.None: Option<'T>
union case Option.Some: Value: 'T -> Option<'T>
val delegateType : obj
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Reflection
module Array

from Microsoft.FSharp.Collections
val create : ast:'a -> mode:Mode -> delegateType:obj option -> env:'b -> T

Full name: Script.Target.create


 Creates a new T record
val ast : 'a
val mode : Mode
val delegateType : obj option
val env : 'a
val createEval : ast:'a -> env:'b -> T

Full name: Script.Target.createEval


 Creates a new T record with Eval mode
val createGlobal : ast:'a -> env:'b -> T

Full name: Script.Target.createGlobal


 Creates a new T record with Global mode
Raw view New version

More information

Link:http://fssnip.net/4c
Posted:5 years ago
Author:fholm
Tags: ml