Example of "dot notation on non-linear values"

52 views
Skip to first unread message

Po-Yu Hsieh

unread,
Jul 8, 2018, 10:17:49 AM7/8/18
to ats-lang-users
I read the symbol overloading part on ATS's wiki (https://github.com/githwxi/ATS-Postiats/wiki/overload). And for the dot-notaiton part, it gives an example for dot-notation on non-linear values.

However the counter examples in ATS documentation (https://github.com/ats-lang/ats-lang.github.io/blob/master/DOCUMENT/ATS2TUTORIAL/CODE/chap_dotoverld.dats) are all for linear values, so I tried to write one based on the code provided in wiki:

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

typedef counter = int

extern fun counter_make (): counter
extern fun counter_get (cntr: !counter): int
extern fun counter_incby (cntr: !counter, n: int): void

overload .get with counter_get
overload .incby with counter_incby

implement counter_make() = 0

implement counter_get (cntr) =
  cntr

implement counter_incby (cntr, n) =
  (
    !cntr := !cntr + n;
    ()
  )

implement main0 () =
let
  val ct = counter_make()
  val _ = println!("Current counter value: ", ct.get)
  val _ = ct.incby(5)
  val _ = println!("Current counter value: ", ct.get)
in
  ()
end

What I really want to try is dot notation for non-linear values without usage of parenthesis (ct.get). But I'm not sure about correctness of this code, and here's the error message the compiler reports:

/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 428(line=21, offs=14) -- 433(line=21, offs=19): error(3): the symbol [!] cannot be resolved as no match is found.
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 428(line=21, offs=14) -- 437(line=21, offs=23): error(3): the symbol [+] cannot be resolved due to too many matches:
D2ITMcst(add_double_int) of 0
D2ITMcst(add_float_int) of 0
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 420(line=21, offs=6) -- 424(line=21, offs=10): error(3): the dynamic expression cannot be dereferenced.
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 551(line=28, offs=49) -- 555(line=28, offs=53): error(3): overloaded dot-symbol: [.get] should be applied.
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 513(line=28, offs=11) -- 556(line=28, offs=54): error(3): the symbol [print] cannot be resolved due to too many matches:
D2ITMcst(print_option) of 0
D2ITMcst(print_list_vt) of 0
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 513(line=28, offs=11) -- 556(line=28, offs=54): error(3): the dynamic expression cannot be assigned the type [S2Ecst(atsvoid_t0ype)].
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 513(line=28, offs=11) -- 556(line=28, offs=54): error(3): mismatch of static terms (tyleq):
The actual term is: S2Eerrexp()
The needed term is: S2Ecst(atsvoid_t0ype)/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 627(line=30, offs=49) -- 631(line=30, offs=53): error(3): overloaded dot-symbol: [.get] should be applied.
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 589(line=30, offs=11) -- 632(line=30, offs=54): error(3): the symbol [print] cannot be resolved due to too many matches:
D2ITMcst(print_option) of 0
D2ITMcst(print_list_vt) of 0
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 589(line=30, offs=11) -- 632(line=30, offs=54): error(3): the dynamic expression cannot be assigned the type [S2Ecst(atsvoid_t0ype)].
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 589(line=30, offs=11) -- 632(line=30, offs=54): error(3): mismatch of static terms (tyleq):
The actual term is: S2Eerrexp()
The needed term is: S2Ecst(atsvoid_t0ype)
patsopt(TRANS3): there are [9] errors in total.
exit(ATS): uncaught exception: _2tmp_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
HPY-KennydeMacBook-Pro:20180708 hpy-kenny$ vim +21 dot_notation.dats
HPY-KennydeMacBook-Pro:20180708 hpy-kenny$ myatscc dot_notation.dats
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 428(line=21, offs=14) -- 433(line=21, offs=19): error(3): the symbol [!] cannot be resolved as no match is found.
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 428(line=21, offs=14) -- 437(line=21, offs=23): error(3): the symbol [+] cannot be resolved due to too many matches:
D2ITMcst(add_double_int) of 0
D2ITMcst(add_float_int) of 0
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 420(line=21, offs=6) -- 424(line=21, offs=10): error(3): the dynamic expression cannot be dereferenced.
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 551(line=28, offs=49) -- 555(line=28, offs=53): error(3): overloaded dot-symbol: [.get] should be applied.
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 513(line=28, offs=11) -- 556(line=28, offs=54): error(3): the symbol [print] cannot be resolved due to too many matches:
D2ITMcst(print_option) of 0
D2ITMcst(print_list_vt) of 0
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 513(line=28, offs=11) -- 556(line=28, offs=54): error(3): the dynamic expression cannot be assigned the type [S2Ecst(atsvoid_t0ype)].
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 513(line=28, offs=11) -- 556(line=28, offs=54): error(3): mismatch of static terms (tyleq):
The actual term is: S2Eerrexp()
The needed term is: S2Ecst(atsvoid_t0ype)
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 627(line=30, offs=49) -- 631(line=30, offs=53): error(3): overloaded dot-symbol: [.get] should be applied.
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 589(line=30, offs=11) -- 632(line=30, offs=54): error(3): the symbol [print] cannot be resolved due to too many matches:
D2ITMcst(print_option) of 0
D2ITMcst(print_list_vt) of 0
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 589(line=30, offs=11) -- 632(line=30, offs=54): error(3): the dynamic expression cannot be assigned the type [S2Ecst(atsvoid_t0ype)].
/Users/hpy-kenny/ats_practice/20180708/dot_notation.dats: 589(line=30, offs=11) -- 632(line=30, offs=54): error(3): mismatch of static terms (tyleq):
The actual term is: S2Eerrexp()
The needed term is: S2Ecst(atsvoid_t0ype)
patsopt(TRANS3): there are [9] errors in total.
exit(ATS): uncaught exception: _2tmp_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)


Julian Fondren

unread,
Jul 8, 2018, 10:37:58 AM7/8/18
to ats-lang-users
Here's an edit that works:

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

typedef counter = ref(int)

extern fun counter_make (): counter
extern fun counter_get (cntr: !counter): int
extern fun counter_incby (cntr: !counter, n: int): void

overload .get with counter_get
overload .incby with counter_incby

implement counter_make() = ref<int>(0)

implement counter_get (cntr) =
  !cntr

implement counter_incby (cntr, n) =
  (
    !cntr := !cntr + n;
    ()
  )

implement main0 () =
let
  val ct = counter_make()
  val _ = println!("Current counter value: ", ct.get())
  val _ = ct.incby(5)
  val _ = println!("Current counter value: ", ct.get())
in
  ()
end

Hongwei Xi

unread,
Jul 8, 2018, 10:44:37 AM7/8/18
to ats-lan...@googlegroups.com

ct.get() is interpreted as dot-notation overloading.
ct.get simply means field selection where ct is expected to be a record.

--
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+unsubscribe@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/1dd169e4-405f-4d96-bd6e-56f4cfda5b56%40googlegroups.com.

Po-Yu Hsieh

unread,
Jul 8, 2018, 11:20:25 AM7/8/18
to ats-lang-users
Because in "Functional dot-notation (linear or non-linear)" section on wiki, it says:

Now this will not typecheck:
val n0 = c0.get


And this gave me the feel that you can write something like this when c0 is a non-linear value and .get is dot-notation overloaded with some function related to c0's type, but the compiler will say that this dot-notation usage should be applied if you try to do so.


gmhwxi於 2018年7月8日星期日 UTC-4上午10時44分37秒寫道:

Hongwei Xi

unread,
Jul 8, 2018, 12:50:55 PM7/8/18
to ats-lan...@googlegroups.com
I took a look. Maybe it was okay to write ct.get (for non-linear ct).

But it is no longer supported. Regardless ct being linear or non-linear, ct.get()
is the proper syntax for dot-notation overloading.

--
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+unsubscribe@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.

Yannick Duchêne

unread,
Jul 8, 2018, 1:02:55 PM7/8/18
to ats-lang-users
Since 2015-05-16, parentheses are required there, but it was not the case before. May be some examples were left untouched.


> 11. Dot-symbol overloading is required to be of functional style.
>      For instance,
>      point.x changes to point.x()
>      point.y changes to point.y()
Reply all
Reply to author
Forward
0 new messages