[MLton] Int Overflow detection

Neophytos Michael nmichael@yahoo.com
Wed, 16 Mar 2005 14:34:24 -0800 (PST)


That's fine but when I interact with the standard lib I give and receive ints
and not words so I have to "decorate" my code with Word.fromInt and
Word32.toIntX which is not very nice or convinient.

For example instead of writting:
------------------------------
fun sum a =
  let
    val l =  (Array.length a)
    fun loop (i, res) =
        if i = l then res
        else loop (i + 1, Array.sub (a, i) + res)
  in
    loop (0, 0.0)
  end
------------------------------

I have to write:
------------------------------
fun sum a =
  let
    val l = Word32.fromInt (Array.length a)
    fun loop (i : Word32.word, res) =
        if i = l then res
        else loop (i + 0w1, Array.sub (a, Word32.toIntX i) + res)
  in
    loop (0w0 : Word32.word, 0.0)
  end
------------------------------

Neophytos

--- Henry Cejtin <henry@sourcelight.com> wrote:
> You use Word, not Int to get that.  (No overflow detection, wrap-around
> arithmetic.)
> 
> _______________________________________________
> MLton mailing list
> MLton@mlton.org
> http://mlton.org/mailman/listinfo/mlton
> 


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Find what you need with new enhanced search. 
http://info.mail.yahoo.com/mail_250