Hi,
I am from an embedded software, C/Python background. I am currently reading Introduction to Programming in ATS and working out the examples therein.
I noticed that when I make some changes to CHAP_DEPDTREF/listfuns.dats, the built binary segfaults. I though of posting it here.
Below are the changes I made:
--- a/doc/BOOK/INT2PROGINATS/CODE/CHAP_DEPDTREF/listfuns.dats
+++ b/doc/BOOK/INT2PROGINATS/CODE/CHAP_DEPDTREF/listfuns.dats
@@ -105,27 +105,29 @@ a,b:t@ype
fun{
a,
b:t@ype}
{c:t@ype
} list_zipwith
{n:nat} .<n>.
(
xs: list (a, n)
, ys: list (b, n)
, f: (a, b) -<cloref1> c
-) : list (c, n) = case+ (xs, ys) of
- | (list_cons (x, xs),
- list_cons (y, ys)) =>
- list_cons{c}(f (x, y), list_zipwith<a,b><c> (xs, ys, f))
- | (list_nil (), list_nil ()) => list_nil ()
+) : list (c, n) = let
+ val zs = list_zip(xs, ys)
+ val f1 = lam(xy:(a,b)) =<cloref1> f(xy.0, xy.1)
+in
+ list_map(zs, f1)
+end
+
// end of [list_zipwith]
(* ****** ****** *)
//
typedef T = int
typedef T2 = (T, T)
//
(* ****** ****** *)
implement
main0 () =
Below is a full listing of a minimal program that is reproducing the crash. I am on Ubuntu 22.04, and am using ATS from the ubuntu package ats2-lang.
$ cat listfuns.dats
#include
"prelude/DATS/integer.dats"
fun{
a:t@ype}
{b:t@ype
} list_map {n:nat} .<n>. (
xs: list (a, n), f: a -<cloref1> b
) : list (b, n) = case+ xs of
| list_cons (x, xs) => list_cons{b}(f x, list_map (xs, f))
| list_nil () => list_nil ()
fun{
a,b:t@ype
} list_zip {n:nat} .<n>.
(
xs: list (a, n), ys: list (b, n)
) : list ((a, b), n) =
(
case+ (xs, ys) of
| (list_cons (x, xs),
list_cons (y, ys)) =>
list_cons{(a, b)}((x, y), list_zip<a,b> (xs, ys))
| (list_nil (), list_nil ()) => list_nil ()
)
fun{
a,
b:t@ype}
{c:t@ype
} list_zipwith
{n:nat} .<n>.
(
xs: list (a, n)
, ys: list (b, n)
, f: (a, b) -<cloref1> c
) : list (c, n) = let
val zs = list_zip(xs, ys)
val f1 = lam(xy:(a,b)) =<cloref1> f(xy.0, xy.1)
in
list_map(zs, f1)
end
implement
main0 () =
{
val xs1 = list_cons(0, list_nil())
val xs2 = list_cons(1, list_nil())
val zs = list_zipwith<int,int><int> (xs1, xs2, lam (x1, x2) => x1 + x2)
}
$ PATSHOME=/usr/lib/ats2-postiats-0.4.2 make listfuns
/usr/lib/ats2-postiats-0.4.2/bin/patsopt -o listfuns_dats.c --dynamic listfuns.dats || echo listfuns_dats.c ": ERROR!!!"
\
gcc -std=c99 -D_GNU_SOURCE -DATS_MEMALLOC_LIBC -I/usr/lib/ats2-postiats-0.4.2 -I/usr/lib/ats2-postiats-0.4.2/ccomp/runtime -O2 -o listfuns listfuns_dats.c || echo listfuns ": ERROR!!!"
$ ./listfuns
Segmentation fault
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04 LTS
Release: 24.04
Codename: noble
$ which patsopt
/usr/bin/patsopt
$ patsopt --version
ATS/Postiats version 0.4.2 with Copyright (c) 2011-2020 Hongwei Xi
$ dpkg -l ats2-lang
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-================-============-===========================================
ii ats2-lang 0.4.2-1.1ubuntu1 amd64 ATS version 2 programming language compiler
$
$
Let me know if you need any other information.
Thanks and regards,
Saravanan.