On 21/01/2026 03:31, Duke Normandin wrote:
Here's the entire code for the "calculator" program. I _did not_ author the code. The author is presumably another PhD in CS somewhere on this planet. https://programming.muthu.co/posts/beginners-guide-to-standard-ml/
[quote] fun add (x: real, y: real) = x + y; fun subtract (x: real, y: real) = x - y; fun multiply (x: real, y: real) = x * y; fun divide (x: real, y: real) = if y = 0.0 then raise DivByZero else x / y; exception DivByZero;
It's not surprising you're having problems. The code on that website has at least two errors. Others have already pointed out that the "real" type is not an equality type so "y = 0.0" is not allowed. But there's a more glaring error in that the exceptions are used before they are declared. It's a general principle in ML that identifiers have to be declared before they are used so the declaration exception DivByZero; needs to be moved above the declaration fun divide ...
It doesn't look as though this code has ever been tested.
I'm sure there are better introductions to Standard ML available. Larry Paulson's book "ML for the Working Programmer" is still available but perhaps rather expensive. Can anyone make any suggestions?
David