Standard ML, Infix identifier ERROR code

…衆ロ難τιáo~ 提交于 2019-12-11 07:22:42

问题


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.

That is

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.


回答1:


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.



来源:https://stackoverflow.com/questions/6320624/standard-ml-infix-identifier-error-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!