避免绑定到固定值,强制调用方法 [英] avoid binding to fix value, force method call

查看:54
本文介绍了避免绑定到固定值,强制调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你好论坛

我有以下代码构造:

let GetClassificationElement = Types.Leaf(分类",Consts.classifications |> ListUtils.ChooseFromList)

let GetClassificationElement = Types.Leaf("Classification", Consts.classifications |> ListUtils.ChooseFromList)

其后被多次调用,并且应该一次又一次地传递分类列表的随机值
(顺便说一句:这种随机选择效果很好).

which is later called multiple times and should deliver again and again a random value of the classification list
(btw: this randomization works perfect).

不幸的是,它仅被调用一次,并且结果值固定在GetClassificationElement上.因此,以后每次使用/分配时,调用方都会获得此修复值

Unfortunatelly it is called only one time and the result value is fixed bound to GetClassificationElement. So for every usage/assignment later, the caller gets this fix value

我可以避免为此功能引入一个(伪)参数i:

I can avoid this be introducing a (fake) parameter i for the function:

let GetClassificationElement i =&Types.Leaf("Classification",Consts.classifications |> ListUtils.ChooseFromList)

let GetClassificationElement i = Types.Leaf("Classification", Consts.classifications |> ListUtils.ChooseFromList)

然后每次调用GetClassificationElement时,它实际上都在运行内部代码.

Then everytime GetClassificationElement is called, it runs really the code inside.

但是这种结构似乎有点奇怪,我认为有更好的解决方案.

But this construct seems to be a litte bit odd and I assume there is a better solution possible.

预先感谢
Webby

Thanks in advance
Webby

推荐答案

let GetClassificationElement()= ...
let GetClassificationElement() = ...


这篇关于避免绑定到固定值,强制调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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