bitwise shift operator not found

85 views
Skip to first unread message

Justin Smith

unread,
Jun 24, 2014, 1:10:18 PM6/24/14
to ats-lan...@googlegroups.com
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.

Brandon Barker

unread,
Jun 24, 2014, 6:02:26 PM6/24/14
to ats-lang-users
My understanding is that this sort of low level mechanism might be best left to implementing (possibly inline) in C:


Brandon Barker
brandon...@gmail.com


--
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.

gmhwxi

unread,
Jun 24, 2014, 10:00:18 PM6/24/14
to ats-lan...@googlegroups.com
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.

gmhwxi

unread,
Jun 24, 2014, 10:22:32 PM6/24/14
to ats-lan...@googlegroups.com
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:
Reply all
Reply to author
Forward
0 new messages