如何处理机器学习中除零错误
我是机器学习新手。
我需要定义一个以条件表达式作为参数的函数,问题是表达式是否无效,如 "10 div 0 = 0"
。我该如何处理这个问题?
例如,函数定义如下:foo exp1 = if (exp1) then ... else...
,而exp1
为"10 div 0 = 0"
,如何处理这个除法错误。
I am new to ML.
I need to define a function taking an conditional expression as argument, the problem is if the expression is invalid like "10 div 0 = 0"
. How can I handle this?
For example, the function is defined as following: foo exp1 = if (exp1) then ... else...
, and exp1
is "10 div 0 = 0"
, how to handle this division error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来你想问一下SML中的异常处理机制。
当您调用
10 div 0
时,SML 基础库中的div
函数会引发 Div 异常。这取决于您是否需要该值来处理异常。在这种情况下,您可以返回 true/false 或选项类型:更新:
在这种情况下,编译器不会引发
Div
异常,这真的很奇怪。我建议您定义一个自定义 div 函数并自己引发/处理异常:It looks like you want to ask about exception handling mechanism in SML.
The
div
function in SML basis library raise Div exception when you invoke10 div 0
. It depends on whether you need the value or not to handle the exception. You can either return true/false or option type in this case:UPDATE:
It is really weird that the compiler doesn't raise
Div
exception in this case. I suggest that you define a custom div function and raise/handle exceptions yourself: