That works, but this is very surprising because I tried what I thought was completely equivalent, and it does not work:
// fails with same error val who: string = (if argc > 1 then ... else ...) On Monday, February 12, 2018 at 8:23:42 AM UTC-6, gmhwxi wrote: > > You need: > > val who = (if argc > 1 then ... else ...): string > > Otherwise, the compiler only knows that string is a subtype of the type > assigned to 'who', which is not enough to support overloading of 'print'. > > > On Mon, Feb 12, 2018 at 2:35 AM, Julian Fondren <julian....@gmail.com > <javascript:>> wrote: > >> The following code works as is: >> >> #include "share/atspre_staload.hats" >> >> implement main0(argc, argv) = >> let >> val who = (if argc > 1 then argv[1] else "world") >> in >> if argc > 1 then >> println!("Hello, ", argv[1], "!"); >> print_string("Hello, "); >> print_string(who); >> print_string("!"); >> print_newline(); >> end >> >> And is used like this: >> >> $ patscc -O2 -flto -D_GNU_SOURCE -DATS_MEMALLOC_LIBC main3.dats -o >> main3 -latslib >> $ ./main3 >> Hello, world! >> $ ./main3 bob >> Hello, bob! >> Hello, bob! >> >> If however the `argv[1]` in `println!` is changed to `who`, >> >> #include "share/atspre_staload.hats" >> >> implement main0(argc, argv) = >> let >> val who = (if argc > 1 then argv[1] else "world") >> in >> if argc > 1 then >> println!("Hello, ", who, "!"); >> print_string("Hello, "); >> print_string(who); >> print_string("!"); >> print_newline(); >> end >> >> then it fails to compile: >> >> main3.dats: 161(line=8, offs=7) -- 190(line=8, offs=36): error(3): >> the symbol [print] cannot be resolved due to too many matches: >> D2ITMcst(print_option) of 0 >> D2ITMcst(print_list_vt) of 0 >> >> -- >> 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 <javascript:>. >> To post to this group, send email to ats-lan...@googlegroups.com >> <javascript:>. >> 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/a763cecd-5120-4c97-b3bb-4537501adadf%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ats-lang-users/a763cecd-5120-4c97-b3bb-4537501adadf%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/6e432f5d-d37c-4f60-b14f-a220b5c89e3e%40googlegroups.com.