Is F # Guidate recommended to declare a module type and its name?

After reading the F # Component Development Guide , I see no comments on whether I should declare a module and its type with the same name.

Usually my projects do not have a cyclical dependency, so I do not need to create a new module (for example, InfrastructureTypesor DomainTypes) to place all types in one place.

For example, if I have a record type Systemand a bunch of its functions, should I put everything in one module file? This is my attempt:

// System.fs
module System

type rec System =
    { name : string
      children : System list }

let init () = { name = ""; children = [] }

let addChild system child =
    { system with system.children = child :: system.children }

let removeChild system child =
    let rec removeChild children acc child =
        match children with
        | c :: children ->
            if c <> child then removeChild children (c :: acc) child
            else removeChild children acc child
        | [] -> List.rev acc

    let children = removeChild system.Children [] child
    { system with system.children = children }
+4
source share
1 answer

F #, ( , ), , List<'a> List, , . Option, Set, Result ..

, , , : [<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]

, F # 4.1, . , , , Module .

type System =
    { name : string
      children : System list }

module System =
    let init () = { name = ""; children = [] }

, , F #. , . , " ", , .

, , , , . , .

+6

Source: https://habr.com/ru/post/1679014/


All Articles