This is caused by a known tail-call optimization bug.
You can circumvent the bug by adding some do-nothing code:

implement(a) myprint<twice(a)>(x) =
  let
    val f = myprint<a>
  in
    f(x);
    f(x);
    () where { val () = () } // do nothing
  end


On Mon, Apr 2, 2018 at 8:18 AM, Andrew Knapp <andy.j.kn...@gmail.com> wrote:

> I can't figure out why this code loops forever. Is it a bug in the
> compiler?
>
> #include "share/atspre_staload.hats"
> #include "share/atspre_define.hats"
>
> staload UN = "prelude/SATS/unsafe.sats"
>
> abst0ype foo(a:t0ype) = lint
> abst0ype twice(a:t0ype) = int
>
> extern fun{a:t@ype} myprint (x: string): void
>
> implement(a) myprint<twice(a)>(x) =
>   let
>     val f = myprint<a>
>   in
>     f(x);
>     f(x);
>   end
>
> implement(a) myprint<foo(a)>(x) =
>   begin
>     print("foo(");
>     myprint<a>(x);
>     print(")");
>   end
>
> implement myprint<int>(x) = print(x)
>
> implement main0() =
>   let
>     val x = "LOOP"
>   in
>     myprint<twice(foo(int))>(x)
>   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-users+unsubscr...@googlegroups.com.
> To post to this group, send email to ats-lang-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/ats-lang-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/ats-lang-users/bf714b63-50da-41c2-9ebc-0f74194572a4%
> 40googlegroups.com
> <https://groups.google.com/d/msgid/ats-lang-users/bf714b63-50da-41c2-9ebc-0f74194572a4%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLr3%3DY7YGOSkfR8AVZhUFSMW1P%3DUHsBjOk-0_y6hut83rQ%40mail.gmail.com.

Reply via email to