Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top