Implementation problem

The purpose of the module described below is to implement a module that, after initialization with integer n, performs all operations based on the value of n.

module ReturnSetZero =
functor ( Elt : int ) ->
    struct
        let rec sublist b e l =
               match l with
           [] -> failwith "sublist"
          | h :: t ->
              let tail = if e = 0 then [] else sublist (b - 1) (e - 1) t in
                    if b > 0 then tail else h :: tail
        let rec zerol = 0:: zerol
        let zeron = sublist 0 n zerol
                (*other operations based on n which is selected once when the module is initialized*)
    end;;

Error: module type Unbound int

What is the problem? Is there a more efficient / intuitive alternative implementation?

+3
source share
1 answer

The functor maps module modules to modules. An integer is not a module, so you cannot use it as a functor parameter.

You need to determine the type of module:

module type WITH_INTEGER = sig
  val integer : int
end

module PrintInteger = 
  functor (Int:WITH_INTEGER) -> struct

  let print_my_integer () = print_int Int.integer

end

, , ( , ), , , , :

let my_function integer = 
  let data = complex_precomputations integer in 
  function arg -> do_something_with arg data

( ).

+2

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


All Articles