Last active
June 28, 2019 05:37
-
-
Save yoshihiro503/9a95f2274f166fffdb73c6b4ddac4e58 to your computer and use it in GitHub Desktop.
erlangのモジュールをたくさん作るOCamlプログラム
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let number_of_modules = | |
if Array.length Sys.argv <= 1 then 100 | |
else Sys.argv.(1) |> int_of_string | |
let create_module_succ index = | |
Printf.sprintf {| | |
-module(mod_%d). | |
-export([f/1]). | |
-spec f(input_%n) -> ok. | |
f(input_%n) -> mod_%n:f(input_%d). | |
|} index index index (index - 1) (index - 1) | |
let create_module_zero = | |
Printf.sprintf {| | |
-module(mod_0). | |
-export([f/1]). | |
-spec f(input_0) -> ok. | |
f(input_0) -> ok. | |
|} | |
let create_module index = | |
if index = 0 then | |
create_module_zero | |
else | |
create_module_succ index | |
let open_file_with filename f = | |
let ch = open_out filename in | |
try | |
let y = f ch in | |
close_out ch; | |
y | |
with | |
e -> close_out ch; | |
raise e | |
let save_module index = | |
let filename = Printf.sprintf "mod_%d.erl" index in | |
prerr_endline (Printf.sprintf "file %s creating..." filename); | |
open_file_with filename (fun ch -> | |
output_string ch (create_module index)) | |
let _ = | |
for i = 0 to number_of_modules-1 do | |
save_module i | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DialyzerとFialyzerの速度比較に使う例