Visual Model For F# – Example 1

Nested modules – example 1

This example shows the possibilities of the created tool when we model modules. They can be nested within each other, as shown in Figure 1

This model illustrats a number of modules that have a function with the same name. In this case, it is simply a function without arguments that returns anything. You can also call it field because it takes no arguments. This field does not have a unique name for the entire model, just that it will be unique within the module in which it is located.

At the top level model, which is in RootModel, we have placed an item called CodeBlock1 CodeBlock. The source code contained in this block is simply a fixed number of value 10. From this element type we can define many relations Link to Function. This means that every function will be defined Function1 body of code that resides in the element CodeBlock.

This example uses the functions as elements included in the modules. Other possible to place there elements are TypeElement classes. In this example, they are not used, but they are equally good items to put them in the model as functions.

Below (Fig. 1) shows an example with nested modules and other elements.

Zagnieżdżone moduły, funkcje i blok koduFigure 1: Nested modules, functions and code block

For the so defined model we get below (Listing 1) piece of source code in F#. You can see that the elements of the diagram are transformed to the corresponding source code.

Levels of nesting of modules can be identified by looking at the indentation in the code. Generated source is consistent with what was presented and discussed in a previous post on modules.

Using the model, one could easily design a simple hierarchy of modules, focusing more on logic than on the entire program, the F# language syntax. It is an advantage that is achieved through-developed tool.

let Function1  =
  10

module ModuleA =
  let Function1  =
    10

  module ModuleAA =
    let Function1  =
      10

module ModuleB =
  let Function1  =
    10

  module ModuleBA =
    module ModuleBAA =
      let Function1  =
        10

    module ModuleBAB =
      let Function1  =
        10

  module ModuleBB =
    let Function1  =
      10

Listing 1: The source code generated from the model of Figure 1

adamex

About Adam Bielasty

.NET Software Developer

One thought on “Visual Model For F# – Example 1

  1. dobry poczatek

Leave a Reply

Your email address will not be published. Required fields are marked *


5 − 5 =

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>