为什么即使我只在一个模块中调用一个函数,我的所有函数仍在运行? [英] Why are all my functions being run even though I'm only calling one function in one module?

查看:51
本文介绍了为什么即使我只在一个模块中调用一个函数,我的所有函数仍在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Test.fs 文件中有以下代码:

I have the following code in a Test.fs file:

namespace Testing

module test1 =
    let Run =
        printfn "Test1"

module test2 =
    let Run =
        printfn "Test2"

在我的 Program.fs 中,我正在呼叫:

In my Program.fs I am calling:

[<EntryPoint>]
let main argv = 
    let sw = Stopwatch.StartNew()

    printfn "%A" Testing.test1.Run

    sw.Stop()
    printfn "Problem took %d minutes, %d seconds, and %d milliseconds" sw.Elapsed.Minutes sw.Elapsed.Seconds sw.Elapsed.Milliseconds

    let s = Console.ReadLine()
    0 // return an integer exit code

此输出

Test1

Test2

为什么即使我只调用 Test1.Run ,也会输出 Test2 吗?

Why is Test2 being outputting even though I am only calling Test1.Run ?

推荐答案

test1.Run 不是函数,而是一个值.当您打开一个模块时,您将执行该模块中的所有顶级代码.在这种情况下,您要定义 test1.Run test2.Run ,它们都是绑定而不是函数.

test1.Run is not a function, it is a value. When you open a module you execute all top-level code in that module. In this case you are defining test1.Run and test2.Run which are both bindings rather than functions.

我不能从您发布的内容中确切知道发生了什么,但是很明显您的主要功能没有被调用,否则 printfn%A" Testing.test1.Run 将打印< null> printfn问题花费了%d分钟,%d秒和%d毫秒" sw.Elapsed.mins sw.Elapsed.Second sw.Elapsed.Milliseconds 也会打印一些东西.

I can't tell from what you posted exactly what is happening, but it's clear that your main function is not getting called, otherwise printfn "%A" Testing.test1.Run would print <null> and printfn "Problem took %d minutes, %d seconds, and %d milliseconds" sw.Elapsed.Minutes sw.Elapsed.Seconds sw.Elapsed.Milliseconds would print something as well.

这篇关于为什么即使我只在一个模块中调用一个函数,我的所有函数仍在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆