调试F#代码和功能样式 [英] Debugging F# code and functional style

查看:133
本文介绍了调试F#代码和功能样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新的功能编程,并对编码风格和调试有一些疑问。

I'm new to funcctional programming and have some questions regarding coding style and debugging.

我的印象是,应该避免存储来自funcction调用的结果在一个临时变量中,然后返回该变量

I'm under the impression that one should avoid storing results from funcction calls in a temp variable and then return that variable

例如

let someFunc foo =
    let result = match foo with
                 | x -> ...
                 | y -> ...
    result 

而是这样做(我可能会离开? ):

And instead do it like this (I might be way off?):

let someFunc foo =
    match foo with
    | x -> ...
    | y -> ...

从功能的角度来看,它工作正常,但它使调试变得更加困难。
我没有办法检查结果,如果右边的 - >做一些时髦的东西。

Which works fine from a functionallity perspective, but it makes it way harder to debug. I have no way to examine the result if the right hand side of -> does some funky stuff.

那么我应该怎么处理这种情况

So how should I deal with this kind of scenarios?

推荐答案

任何一种方式都可以接受,因为您只是绑定到本地不可变的变量。

Either way is acceptable, as you are simply binding to local immutable variable.

有一个catch。如果您使用尾随调用作为递归循环的一部分,那么使用临时变量的消息将消除尾部调用,因此您将增加堆栈空间。

There is a catch though. If you using it as part of a recursive loop using tail calls, the one using the temp variable will eliminate the tail call, and hence you will have an increase in stack space.

这篇关于调试F#代码和功能样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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