Search code examples
ats

How to turn an integer into a double in ATS?


Could someone tell me how to implement the following function in ATS:

fun int2double (x: int): double

Thanks!


Solution

  • It depends on the target language you want to compile to.

    If you compile to C, you can just do:

    staload
    UN = "prelude/SATS/unsafe.sats"
    
    fun int2double(x: int): double = $UN.cast(x)
    

    If you compile to JavaScript, then int2double is already defined.