>>val who: string = (if argc > 1 then ... else ...)

The pattern 'who: string' means that whatever matches
it should have a type X <= string.

This is something that I hope to be able to properly address in ATS3.

On Monday, February 12, 2018 at 11:36:02 AM UTC-5, Julian Fondren wrote:
>
> 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> 
>> 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.
>>> To post to this group, send email to ats-lan...@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/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/6bc21401-4289-40f2-8abc-c72f16dcbb15%40googlegroups.com.

Reply via email to