Is there "uint32" literal on ATS language?

Yes, there are int8/uint8, int16/uint16, int32/uint32 and int64/uint64.

Operations on these types are declared in prelude/integer_fixed.satsOn Sat, Nov 22, 2014 at 9:10 AM, Kiwamu Okabe kiw...@debian.or.jp wrote:

Hi,

I re-write some C language programs using ATS language.
However, the programs use “uint32” and “uint16”, “uint8” many times.

Is there “uint32” literal on ATS language?

Thank’s,

Kiwamu Okabe at METASEPI DESIGN


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmimOKsT6%3DaUym2nLqxOfXqbjCEyWkjPG%2BypDZDVPDb2A%40mail.gmail.com
.

I don’t understand why some types have a literal, and the other types
have no literal.
Which is the boundary line?

In this case, the reason is that there is no special literal representation
for values of the type uint32_t in C. So casting/coercion is needed in C
as well, albeit it is done implicitly in C.On Tuesday, November 25, 2014 6:31:10 AM UTC-5, Kiwamu Okabe wrote:

Hi,

On Mon, Nov 24, 2014 at 4:18 AM, gmhwxi <gmh...@gmail.com <javascript:>> wrote:

implement{} u32_int (x) = $UN.cast(x)
implement{} u32_uint (x) = $UN.cast(x)

I think it’s useful for me.
May I have the other question?

“Essentially, uint32 literal needs cast thing?
Is there a way to define the literal directly?”

I don’t understand why some types have a literal, and the other types
have no literal.
Which is the boundary line?

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

I would just do a cast. For instance, $UN.cast{uint32}(100U)On Sunday, November 23, 2014 12:05:56 AM UTC-5, Kiwamu Okabe wrote:

Hi Hongwei,

On Sun, Nov 23, 2014 at 2:50 AM, Hongwei Xi <gmh...@gmail.com <javascript:>> wrote:

Yes, there are int8/uint8, int16/uint16, int32/uint32 and int64/uint64.

Ah, I think I know that.
I think “80U” is for “uint” literal and “80UL” is for “ullint” literal.
Then what is for “uint32” literal?

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

Is there more better way?

As I see it, the problem with providing a better way to do this is that
a user has to learn it.

Without explicit casting, ATS could be notoriously difficult to use.
One often had to spend hours before one could even learn how to implement
a simple program like 'Hello, world!".

While $UN.cast may look ugly, it can get you going without having to learn
a new feature first. As one’s knowledge of ATS picks up, one should be able
to reduce the use of $UN.cast if it is desired.On Sunday, November 23, 2014 8:38:21 AM UTC-5, Kiwamu Okabe wrote:

Hi,

On Sun, Nov 23, 2014 at 2:26 PM, gmhwxi <gmh...@gmail.com <javascript:>> wrote:

I would just do a cast. For instance, $UN.cast{uint32}(100U)

Umm… I found the cast occurred some template error, in the past.
And I think many programmers will get a surprise using such cast many
times.

Is there more better way?

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

Here is a way that may be better:

staload
UN = “prelude/SATS/unsafe.sats”

#define pow2_31 0x80000000
#define pow2_32 0x100000000
extern
fun{} u32_int{i:nat | i < pow2_31} (int(i)): uint32(i)
extern
fun{} u32_uint{i:nat | i < pow2_32} (uint(i)): uint32(i)

implement{} u32_int (x) = $UN.cast(x)
implement{} u32_uint (x) = $UN.cast(x)

(* ****** ****** *)

postfix u32
symintr u32
overload u32 with u32_int
overload u32 with u32_uint

val x = (100)u32
val x = (100u)u32

(* ****** ****** *)

postfix _u32
symintr _u32
overload _u32 with u32_int
overload _u32 with u32_uint

val x = 100_u32
val x = 100u_u32

(* ****** ****** *)On Sunday, November 23, 2014 8:38:21 AM UTC-5, Kiwamu Okabe wrote:

Hi,

On Sun, Nov 23, 2014 at 2:26 PM, gmhwxi <gmh...@gmail.com <javascript:>> wrote:

I would just do a cast. For instance, $UN.cast{uint32}(100U)

Umm… I found the cast occurred some template error, in the past.
And I think many programmers will get a surprise using such cast many
times.

Is there more better way?

Thank’s,

Kiwamu Okabe at METASEPI DESIGN

Essentially, uint32 literal needs cast thing?

Yes. Otherwise, we have to do something about lexing/parsing in ATS.
I don’t feel it is worth it. If x is an integer, $UN.cast{uint32}(x) is
simply
treated as x once typechecking is finished.

Is there a way to define the literal directly?

The only other way I can think of is to do something like:

$extval(uint32, “123”)On Tuesday, November 25, 2014 6:31:10 AM UTC-5, Kiwamu Okabe wrote:

Hi,

On Mon, Nov 24, 2014 at 4:18 AM, gmhwxi <gmh...@gmail.com <javascript:>> wrote:

implement{} u32_int (x) = $UN.cast(x)
implement{} u32_uint (x) = $UN.cast(x)

I think it’s useful for me.
May I have the other question?

“Essentially, uint32 literal needs cast thing?
Is there a way to define the literal directly?”

I don’t understand why some types have a literal, and the other types
have no literal.
Which is the boundary line?

Thank’s,

Kiwamu Okabe at METASEPI DESIGN