1

As explained in the REAL signature, real type defined in SML is not an equality type and hence the following expression does not reduces

> 1.0 = 1.0;
poly: : error: Type error in function application.
   Function: = : ''a * ''a -> bool
   Argument: (1.0, 1.0) : real * real
   Reason: Can't unify ''a to real (Requires equality type)

However, this is not handy as datatypes and lists containing reals, lose equality too. I would need to overload polymorphic equality = with Real.== so it could approximately consider reals too.

Is that possible ?

EDIT: Edited question to be more clear

2 Answers2

3

Did you read Why can't I compare reals in Standard ML and consider the Real.== operator or perform an epsilon test? Have you considered a type like Haskell's Data.Decimal (in which the mantissa and exponent are handled as a pair of Integer)?

Community
  • 1
  • 1
sshine
  • 15,635
  • 1
  • 41
  • 66
  • Yes, I have already read that Stack Overflow post. My question is "Can I overload `=` with `Real.==`" ? Because I need to use reals in datatypes and lists – Hai Nguyen Van Mar 03 '17 at 16:48
1

The simple answer is: no, you can't.

Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72