How to avoid an unsolved constraint error on `if pagesizes > 0UL then pagesizes else 1UL`

19 views
Skip to first unread message

Kiwamu Okabe

unread,
Mar 31, 2021, 8:31:04 AM3/31/21
to ats-lang-users
Dear all,

I wrote following ATS code:

```ats
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"

fun concat_rnd_base {i:int | i > 0} (align: ulint i): ulint =
undefined()

fun concat_exec_imgact {i:int} (pagesizes: ulint i): ulint = let
val psize = if pagesizes > 0UL then pagesizes else 1UL
in
concat_rnd_base(psize)
end

implement main0 () = {
}
```

but above code causes following error:

```
$ patscc main.dats
.../main.dats: 302(line=10, offs=21) -- 307(line=10, offs=26):
error(3): unsolved constraint: C3NSTRprop(C3TKmain();
S2Eeqeq(S2Evar(i(8481)); S2Eintinf
(1)))
```

I belive the `psize` depends on `{i:int | i > 0}`.
How to avoid the unsolved constraint error?

Best regards,
--
Kiwamu Okabe at METASEPI DESIGN

Hongwei Xi

unread,
Mar 31, 2021, 9:08:54 AM3/31/21
to ats-lan...@googlegroups.com
For such a use, you need a type annotation:

fun concat_exec_imgact {i:int} (pagesizes: ulint i): ulint = let
val
psize =
(

if
pagesizes > 0UL
then pagesizes else 1UL
) : [i:pos] ulint(i)
in
  concat_rnd_base(psize)
end

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dnue3oRHsd0oFR9R1Y0WjsGfOu2YfYJ2pvpOm8mBHQBPQ%40mail.gmail.com.

Kiwamu Okabe

unread,
Mar 31, 2021, 6:43:48 PM3/31/21
to ats-lang-users
Thanks. It works!
Reply all
Reply to author
Forward
0 new messages