Bitwise shift operator not found

fun first1 {ndx:int | ndx >= 1} (ndx: ulint ndx, nzer: ulint): (ulint, ulint
) =
if (ndx land 1ul) = 0ul
then first1 ((ndx >> 1ul), nzer + 1ul)
else (ndx, nzer)

the above code gives the following error:

error(3): the symbol [>>] cannot be resolved as no match is found.

as you can see, I tried to introduce a dependent type, mostly in
speculation of the conditions where the compiler would approve of a bit
shift, or consider it “safe”

Is there a general overview for bitwise operations in ats2? I haven’t been
able to find anything in the html book from the main site.

ndx >> 1ul

should be

ndx >> 1

However, the typechecker does not know that ndx >> 1 yields a nonzero
integer in this case. So you
will encounter a type-error.On Tuesday, June 24, 2014 1:10:18 PM UTC-4, Justin Smith wrote:

fun first1 {ndx:int | ndx >= 1} (ndx: ulint ndx, nzer: ulint): (ulint,
ulint) =
if (ndx land 1ul) = 0ul
then first1 ((ndx >> 1ul), nzer + 1ul)
else (ndx, nzer)

the above code gives the following error:

error(3): the symbol [>>] cannot be resolved as no match is found.

as you can see, I tried to introduce a dependent type, mostly in
speculation of the conditions where the compiler would approve of a bit
shift, or consider it “safe”

Is there a general overview for bitwise operations in ats2? I haven’t been
able to find anything in the html book from the main site.

This version typechecks:

fun
first1{i:pos}
(
ndx: ulint(i), nzer: uint
) : (ulint, uint) =
(
if
iseqz (ndx land 1ul)
then let
val ndx = ndx >> 1
val [i:int] ndx = g1ofg0 (ndx)
prval () = __assert () where
{
extern praxi __assert (): [i >= 1] void
}
in
first1 (ndx, succ(nzer))
end // end of [then]
else (ndx, nzer) // end of [else]
) (* end of [first1] *)On Tuesday, June 24, 2014 1:10:18 PM UTC-4, Justin Smith wrote:

fun first1 {ndx:int | ndx >= 1} (ndx: ulint ndx, nzer: ulint): (ulint,
ulint) =
if (ndx land 1ul) = 0ul
then first1 ((ndx >> 1ul), nzer + 1ul)
else (ndx, nzer)

the above code gives the following error:

error(3): the symbol [>>] cannot be resolved as no match is found.

as you can see, I tried to introduce a dependent type, mostly in
speculation of the conditions where the compiler would approve of a bit
shift, or consider it “safe”

Is there a general overview for bitwise operations in ats2? I haven’t been
able to find anything in the html book from the main site.

My understanding is that this sort of low level mechanism might be best
left to implementing (possibly inline) in C:
http://www.ats-lang.org/DOCUMENT/INT2PROGINATS/HTML/c1995.html

Brandon Barker
brandon…@gmail.comOn Tue, Jun 24, 2014 at 1:10 PM, Justin Smith noise...@gmail.com wrote:

fun first1 {ndx:int | ndx >= 1} (ndx: ulint ndx, nzer: ulint): (ulint,
ulint) =
if (ndx land 1ul) = 0ul
then first1 ((ndx >> 1ul), nzer + 1ul)
else (ndx, nzer)

the above code gives the following error:

error(3): the symbol [>>] cannot be resolved as no match is found.

as you can see, I tried to introduce a dependent type, mostly in
speculation of the conditions where the compiler would approve of a bit
shift, or consider it “safe”

Is there a general overview for bitwise operations in ats2? I haven’t been
able to find anything in the html book from the main site.


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/d5769810-8030-4a1d-8aa9-7d640d47f66b%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/d5769810-8030-4a1d-8aa9-7d640d47f66b%40googlegroups.com?utm_medium=email&utm_source=footer
.