kfl / mosml

Moscow ML is a light-weight implementation of Standard ML (SML), a strict functional language widely used in teaching and research.
http://mosml.org
341 stars 42 forks source link

IntInf.int is not eqtype #34

Closed hebiyan closed 9 years ago

hebiyan commented 9 years ago

I wrote this code in MacOS X 10.9.5 using mosml 2.10 installed from pkg file.

$ rlwrap mosml
Moscow ML version 2.10
Enter `quit();' to quit.
- load "IntInf";
> val it = () : unit
- IntInf.fromInt 1 = IntInf.fromInt 1;
! Toplevel input:
! IntInf.fromInt 1 = IntInf.fromInt 1;
! ^^^^^^^^^^^^^^^^
! Type clash: expression of type
!   int/1
! cannot have equality type ''a
-

According to the basis library document (http://sml-family.org/Basis/int-inf.html#section:0), signature INT_INF includes INTEGER, and INTEGER has eqtype int. So, I should write like "IntInf.fromInt 1 = IntInf.fromInt 1" using comparison operators. Could you show me why IntInf is not eqtype, please?

Sorry for my poor english. Thank you.

kfl commented 9 years ago

Unfortunately mosml's implementation of IntInf is not standard compliant wrt eqtype of the IntInf.int type.

However, you can compare IntInf.int values by using either IntInf.eq or IntInf.compare:

- infix ==
val op == = IntInf.eq;
> infix 0 ==
  val == = fn : int/1 * int/1 -> bool
- IntInf.fromInt 1 == IntInf.fromInt 1;
> val it = true : bool