When I encounter a segfault, it is usually caused by recursion depth being
over some kind of limit.

In your code, the 'aux' function is defined but never called. Here is a
fixed version:

fun
{a: t@ype}
brauntest1 (t0: tree a): bool =
  let exception Negative of ()
      fun aux (t0: tree a): bool =
        case+ t0 of
          | tree_nil () => true
          | tree_cons (tl, _, tr) =>
              let val szl = size<a> (tl)
                  val szr = size<a> (tr)
              in
                if abs (szl - szr) > 1 then $raise Negative ()
                  else aux(tl) andalso aux(tr)
              end
  in
    try aux(t0) with ~Negative () => false
  end

On Thu, Aug 20, 2020 at 6:46 AM Timmy Jose <zoltan.j...@gmail.com> wrote:

>
>
> Hi,
>
> I have a variation of the Braun Tree test (where the size of the left and
> right subtrees differ by at most 1 at every level) from the tutorials, and
> this one, for some reason gives a segmentation fault.
>
> Here is the snippet:
>
> fun
> {a: t@ype}
> brauntest1 (t0: tree a): bool =
>   let exception Negative of ()
>       fun aux (t0: tree a): bool =
>         case+ t0 of
>           | tree_nil () => true
>           | tree_cons (tl, _, tr) =>
>               let val szl = size<a> (tl)
>                   val szr = size<a> (tr)
>               in
>                 if abs (szl - szr) > 1 then $raise Negative ()
>                   else brauntest1<a> (tl) andalso brauntest1<a> (tr)
>               end
>   in
>     try brauntest1 (t0) with ~Negative () => false
>   end
>
> And here is the output from `lldb` (gdb has some code-signing issues on
> macOS).
>
> $ lldb braun
> (lldb) target create "braun"
> Current executable set to 'braun' (x86_64).
> (lldb) r
> Process 28137 launched: '<path elided>/braun' (x86_64)
> Process 28137 stopped
> * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS
> (code=2, address=0x7ffeef3fff68)
>     frame #0: 0x0000000100001577 braun`brauntest1_3__3__1 + 39
> braun`brauntest1_3__3__1:
> ->  0x100001577 <+39>: callq  0x100001c3a               ; symbol stub for:
> setjmp
>     0x10000157c <+44>: testl  %eax, %eax
>     0x10000157e <+46>: je     0x1000015de               ; <+142>
>     0x100001580 <+48>: movq   0xb31(%rip), %rcx         ;
> my_atsexnframe_getref.my_atsexnframe
> Target 0: (braun) stopped.
> (lldb)
>
> Anybody seen this before, or have an idea what might be going wrong?
>
> Thanks!
>
> Timmy
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/ad557181-8986-4784-a724-2f2bba9cd5d9n%40googlegroups.com
> <https://groups.google.com/d/msgid/ats-lang-users/ad557181-8986-4784-a724-2f2bba9cd5d9n%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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqhKexD7BhuSSGF9EUZ9cqz%2BZJ-nWg-2s1Tz7JeZWFwMA%40mail.gmail.com.

Reply via email to