标准ML,中缀标识符ERROR代码 [英] Standard ML, Infix identifier ERROR code

查看:68
本文介绍了标准ML,中缀标识符ERROR代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

exception div;  
fun f(x,y) =   
    let  
        val before = 2.0 * x + 3.0 * y  
    in   
        (before + (1.0 / (if x > 0.0001 then x else raise div)) + 2.0 / y) handle div => before / 6.0
    end

此代码会产生一些编译错误.

This code yields some compile error.

那是

e.sml:4.8-4.14错误:表达式或模式以中缀标识符"before"开头
e.sml:6.8-6.14错误:表达式或模式以中缀标识符"before"开头
e.sml:6.57-6.60错误:表达式或模式以中缀标识符"div"开头
e.sml:6.81-6.84错误:表达式或模式以中缀标识符"div"开头
e.sml:6.88-6.94错误:表达式或模式以中缀标识符"before"开头

e.sml:4.8-4.14 Error: expression or pattern begins with infix identifier "before"
e.sml:6.8-6.14 Error: expression or pattern begins with infix identifier "before"
e.sml:6.57-6.60 Error: expression or pattern begins with infix identifier "div"
e.sml:6.81-6.84 Error: expression or pattern begins with infix identifier "div"
e.sml:6.88-6.94 Error: expression or pattern begins with infix identifier "before"

为什么会发生此错误? 我没有使用中缀代码,而只是使用了变量和异常.

Why this error occured? I didn't use infix code, but just use variable and exception.

推荐答案

beforediv是SML基础库中定义的中缀运算符,因此您不能将它们用作变量或异常的名称,而覆盖它们的中缀首先声明.

before and div are infix operators defined in SML's Basis library, so you can't use them as names for variables or exceptions with overriding their infix declaration first.

这篇关于标准ML,中缀标识符ERROR代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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