# Compiler warnings

**URL:** <https://discourse.ats-lang.org/t/compiler-warnings/715>\
**Category:** Google Group\
**Created:** [October 29, 2015, 1:58pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715 "2015-10-29T13:58:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [October 29, 2015, 1:58pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/1 "2015-10-29T13:58:05Z")

</div>

My application has lots of warnings like shown below. Should I be trying to  
remove these or are they typical of ATS application and to be ignored? Are  
there some standard compiler flags that would turn off things that should  
be ignored?

To take a particular case, the first error about const, I have the  
following C declarations:

uint8\_t packetIn[127];  
const uint8\_t \*packetInCount = packetIn;  
const uint8\_t \*packetInHeader = packetIn + 1;

The idea being there are some pointers into a block of data that never  
change.

And, I assume arrayref does some kind of implicit cast and then there is a  
warning. Note, I am not a C compiler expert, so I’m doing some guessing  
here.

DATS/frames\_dats.c: In function ‘process\_smbus\_frame\_command\_138’:  
DATS/frames\_dats.c:9714:1: warning: passing argument 1 of  
‘ATSLIB\_056\_prelude\_\_arrayref\_get\_at\_gint\_\_20\_\_5’ discards ‘const’  
qualifier from pointer target type [enabled by default]  
ATSINSmove(tmp356,  
ATSLIB\_056\_prelude\_\_arrayref\_get\_at\_gint\_\_20\_\_5(ATSPMVextval(packetInContents),  
ATSPMVi0nt(0))) ;  
^  
DATS/frames\_dats.c:861:1: note: expected ‘atstype\_ptrk’ but argument is of  
type ‘const uint8\_t \*’  
ATSLIB\_056\_prelude\_\_arrayref\_get\_at\_gint\_\_20\_\_5(atstkind\_type(atstype\_ptrk),  
atstkind\_t0ype(atstype\_int)) ;  
^  
patsopt -o DATS/main\_dats.c.tmp -d DATS/main.dats  
mv DATS/main\_dats.c.tmp DATS/main\_dats.c  
avr-gcc -g -Wall -O2 -mmcu=atmega328p -DF\_CPU=16000000UL -std=c99  
-D\_XOPEN\_SOURCE -D\_ATSTYPE\_VAR\_SIZE\_=0X000F -D\_ATS\_CCOMP\_EXCEPTION\_NONE\_  
-D\_ATS\_CCOMP\_RUNTIME\_NONE\_ -D\_ATS\_CCOMP\_PRELUDE\_NONE\_  
-D\_ATS\_CCOMP\_PRELUDE\_USER\_="/home/mike/linti/libs/arduino-ats/avr\_prelude/kernel\_prelude.cats"  
-Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable -I.  
-I/opt/ATS/ATS2-Postiats-0.2.4 -I/opt/ATS/ATS2-Postiats-0.2.4/ccomp/runtime  
-I/home/mike/linti/libs/arduino-ats/\_arduino  
-I/home/mike/linti/libs/arduino-ats/\_dummy  
-I/home/mike/linti/libs/arduino-ats -c -o DATS/main\_dats.o DATS/main\_dats.c  
DATS/main\_dats.c:333:1: warning: ‘output\_high\_1’ defined but not used  
[-Wunused-function]  
output\_high\_1(atstkind\_t0ype(atstype\_int) arg0)  
^  
DATS/main\_dats.c:363:1: warning: ‘input\_2’ defined but not used  
[-Wunused-function]  
input\_2(atstkind\_t0ype(atstype\_int) arg0)

---

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [November 3, 2015, 2:34am UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/2 "2015-11-03T02:34:10Z")

</div>

The template approach will allow more or lesser number of functions rather  
than requiring a fixed interface, with possible throwing of exceptions for  
the unimplemented. This does have merit, so I will give this a go.

The Haskell approach was in reaction to several attempts that failed in one  
way or another and this was the best of multiple alternatives. I’m not  
stuck on it if there is a better approach.

---

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [November 2, 2015, 3:17pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/3 "2015-11-02T15:17:28Z")

</div>

I think that ultimately, a closure is required to capture a moniker used by  
an implementation of an interface, to do what the Haskell example does.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 30, 2015, 9:39pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/4 "2015-10-30T21:39:00Z")

</div>

As a programmer, you can have precise control over template instantiation.

Of course, to stop inlining, you need to have control over the C compiler  
you use as well.On Fri, Oct 30, 2015 at 5:28 PM, Hongwei Xi [gmh...@gmail.com](mailto:gmh...@gmail.com) wrote:

> That is correct.
> 
> On Fri, Oct 30, 2015 at 5:12 PM, Mike Jones [proc...@gmail.com](mailto:proc...@gmail.com) wrote:
> 
> > And if you use templates everywhere, it global optimizes, but the image  
> > is bigger due to inlining. Correct?
> > 
> > –  
> > 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](mailto:ats-lang-user...@googlegroups.com).  
> > To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/ats-lang-users/400a6d0b-7c22-4baf-8c15-d7de7de21f36%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/400a6d0b-7c22-4baf-8c15-d7de7de21f36%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/ats-lang-users/400a6d0b-7c22-4baf-8c15-d7de7de21f36%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/400a6d0b-7c22-4baf-8c15-d7de7de21f36%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [November 2, 2015, 3:01pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/5 "2015-11-02T15:01:46Z")

</div>

I think I completely understand what you want here.

In ATS, this sort thing can be done based templates, requiring no use of  
boxed types.

abstype devtype // for SMBus

extern  
fun{devtype}  
sendByte : (Address, Command, err: &int \>\> \_): SMBusStatus

implement  
sendByte (A, C, err) = …On Mon, Nov 2, 2015 at 9:07 AM, Mike Jones [proc...@gmail.com](mailto:proc...@gmail.com) wrote:

> wrt Haskell
> 
> See this for background:
> 
> [24 Days of GHC Extensions: Type Families](https://ocharles.org.uk/blog/posts/2014-12-12-type-families.html)  
> [24 Days of GHC Extensions: Record Wildcards](https://ocharles.org.uk/blog/posts/2014-12-04-record-wildcards.html)
> 
> A specific example sets up a data type as an interface:
> 
> data SMBus = SMBus {  
> sendByte :: Address → Command → IO (Either SMBusStatus ()),  
> writeByte :: Address → Command → Word8 → IO (Either SMBusStatus ()),  
> readByte :: Address → Command → IO (Either SMBusStatus Word8),  
> writeWord :: Address → Command → Word16 → IO (Either SMBusStatus ()),  
> readWord :: Address → Command → IO (Either SMBusStatus Word16),  
> readBlock :: Address → Command → Size → IO (Either SMBusStatus  
> [Char]),  
> readString :: Address → Command → Size → IO (Either SMBusStatus  
> String),  
> probe :: () → IO (Maybe [Address]),  
> close :: () → IO (),  
> }
> 
> And there are multiple instances with one partial example here:
> 
> smbusAardvark = do  
> devices ← devices – From USB API  
> handle ← A.openDevice (head devices) – Don’t get hung up on how  
> dangerous this is to assume the first device, yes it is  
> return $ SMBus {  
> sendByte = \address command → do  
> (status, numWritten) ← i2cWriteExt (fromIntegral handle)  
> (fromIntegral address) I2cNoFlags [(fromIntegral command)] 1  
> ss ← toStatus status  
> if ss == SMBusOk then return $ Right () else return $ Left ss,
> 
> And calling code creates an instance for a particular hardware interface,  
> such that it returns a SMBus datatype with the handle and operations hidden  
> behind it.
> 
> The goal is to instance whatever hardware is being used.
> 
> smbus ← smbusAardvark
> 
> runI2cTest :: SMBus → IO ()  
> runI2cTest smbus@SMBus{…} = do
> 
> ```
> s <- writeByte 0x30 0x00 0x00
> 
> ```
> 
> In my current application context, it might mean the code listens to some  
> interface, then makes decisions about what interface to frame over, then  
> instance an interface for it. This means all code that consumes the  
> interface is the same.
> 
> That said, because it is embedded, I would like to avoid boxed types.  
> Passing in memory from an outer frame, such that it remains on the stack  
> might be ok, but it would be better to be static. One issue is that  
> depending on the instance chosen, the memory size changes. So if the choice  
> was to preallocate space with C, it would be nice to have a way for the  
> code to statically calculate a maximum so that there are no accidental  
> overflows, or to specify its size, and use statics to prevent code from  
> instantiating something bigger than what was pre-allocated.
> 
> RecordWildCards are not necessary, they just pretty up the code so it  
> reads out loud better.
> 
> –  
> 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](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/2e8f4c84-4615-45ce-a851-4b89c8061543%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/2e8f4c84-4615-45ce-a851-4b89c8061543%40googlegroups.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/2e8f4c84-4615-45ce-a851-4b89c8061543%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/2e8f4c84-4615-45ce-a851-4b89c8061543%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 31, 2015, 12:06am UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/6 "2015-10-31T00:06:23Z")

</div>

Yes! ATS code would run rather slowly if it is not eventually being  
optimized aggressively by C. Patsopt, the ATS compiler, creates  
opportunities for the subsequently called C compiler but it itself does  
not actually perform any optimizations (except for tail-call optimization,  
which is indispensable for a language that strongly advocates the use  
of tail-recursion to replace loops).On Friday, October 30, 2015 at 7:46:41 PM UTC-4, Barry Schwartz wrote:

> Mike Jones \<[pro...@gmail.com](mailto:pro...@gmail.com) \<javascript:\>\> skribis:
> 
> > Ok, so you are saying using templates enables inlining, but does not  
> > enforce it. You can always find a compiler setting to prevent it.
> 
> Indeed, inlining by the C compiler is such a big boost in the  
> performance of ATS code (and I think unlikely to be a serious  
> hindrance to debugging) that I am having my autoconf scripts turn on  
> GCC’s inlining optimizations aggressively when compiling ATS code,  
> even when other optimizations are turned off by the user. (I usually  
> use -Og for my own code. It’s not very aggressive.)

---

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [November 2, 2015, 2:07pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/7 "2015-11-02T14:07:31Z")

</div>

wrt Haskell

See this for background:

[https://ocharles.org.uk/blog/posts/2014-12-12-type-families.html](https://ocharles.org.uk/blog/posts/2014-12-12-type-families.html)  
[https://ocharles.org.uk/blog/posts/2014-12-04-record-wildcards.html](https://ocharles.org.uk/blog/posts/2014-12-04-record-wildcards.html)

A specific example sets up a data type as an interface:

data SMBus = SMBus {  
sendByte :: Address -\> Command -\> IO (Either SMBusStatus ()),  
writeByte :: Address -\> Command -\> Word8 -\> IO (Either SMBusStatus ()),  
readByte :: Address -\> Command -\> IO (Either SMBusStatus Word8),  
writeWord :: Address -\> Command -\> Word16 -\> IO (Either SMBusStatus ()),  
readWord :: Address -\> Command -\> IO (Either SMBusStatus Word16),  
readBlock :: Address -\> Command -\> Size -\> IO (Either SMBusStatus [Char]),  
readString :: Address -\> Command -\> Size -\> IO (Either SMBusStatus  
String),  
probe :: () -\> IO (Maybe [Address]),  
close :: () -\> IO (),  
}

And there are multiple instances with one partial example here:

smbusAardvark = do  
devices \<- devices – From USB API  
handle \<- A.openDevice (head devices) – Don’t get hung up on how  
dangerous this is to assume the first device, yes it is  
return $ SMBus {  
sendByte = \address command -\> do  
(status, numWritten) \<- i2cWriteExt (fromIntegral handle)  
(fromIntegral address) I2cNoFlags [(fromIntegral command)] 1  
ss \<- toStatus status  
if ss == SMBusOk then return $ Right () else return $ Left ss,

And calling code creates an instance for a particular hardware interface,  
such that it returns a SMBus datatype with the handle and operations hidden  
behind it.

The goal is to instance whatever hardware is being used.

smbus \<- smbusAardvark

runI2cTest :: SMBus -\> IO ()  
runI2cTest smbus@SMBus{…} = do

```
s <- writeByte 0x30 0x00 0x00

```

In my current application context, it might mean the code listens to some  
interface, then makes decisions about what interface to frame over, then  
instance an interface for it. This means all code that consumes the  
interface is the same.

That said, because it is embedded, I would like to avoid boxed types.  
Passing in memory from an outer frame, such that it remains on the stack  
might be ok, but it would be better to be static. One issue is that  
depending on the instance chosen, the memory size changes. So if the choice  
was to preallocate space with C, it would be nice to have a way for the  
code to statically calculate a maximum so that there are no accidental  
overflows, or to specify its size, and use statics to prevent code from  
instantiating something bigger than what was pre-allocated.

RecordWildCards are not necessary, they just pretty up the code so it reads  
out loud better.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 30, 2015, 11:59pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/8 "2015-10-30T23:59:18Z")

</div>

One consequence of template instantiation is bringing the definition of a  
template to the place where  
the template is used. In this way, it creates an opportunity of the C  
compiler to actually perform inlining.

A non-template function is still while a function template is mobile (in  
the sense that its code gets moved  
around by the ATS compiler).On Friday, October 30, 2015 at 7:26:51 PM UTC-4, Mike Jones wrote:

> Ok, so you are saying using templates enables inlining, but does not  
> enforce it. You can always find a compiler setting to prevent it.
> 
> I am basing this on a comment in another thread where I had a function  
> like u73 that clamped a value, and you suggested templates so that it would  
> be inlined.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 30, 2015, 1:19pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/9 "2015-10-30T13:19:21Z")

</div>

> > Given that, if all functions in G are templates, and all functions in C  
> > and D are templates, will all the template expansions end up in M like you  
> > recommend?

Yes, all the template expansions end up in M as can be expected.

> > If so, I can have my cake and eat it 🙂

Yes, both 🙂

By the way, the ‘and’ in the above sentence is linear (as in linear logic).On Friday, October 30, 2015 at 9:13:02 AM UTC-4, Mike Jones wrote:

> I see the point about full optimization, but now I have to consider that  
> if I break a large application into multiple files, I have dependencies  
> like:
> 
> A depends B == a → B
> 
> so
> 
> C → G  
> D → G  
> M → C && D
> 
> So there is then no way to get all the templates to expand in M (Main)
> 
> The same would happen when using a library in prelude or contrib in a  
> multiple application.
> 
> Given that, if all functions in G are templates, and all functions in C  
> and D are templates, will all the template expansions end up in M like you  
> recommend?
> 
> If so, I can have my cake and eat it 🙂

---

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [October 30, 2015, 9:12pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/10 "2015-10-30T21:12:31Z")

</div>

And if you use templates everywhere, it global optimizes, but the image is  
bigger due to inlining. Correct?

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [November 2, 2015, 4:12am UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/11 "2015-11-02T04:12:21Z")

</div>

The hope is that the resulting code is smaller in size. It may be slower  
but not necessarily.

In this particular case, the loop is just too simple. But it should not be  
hard to imagine a scenario  
where using a higher-order function allows the code size to go down.On Sunday, November 1, 2015 at 10:20:10 PM UTC-5, Mike Jones wrote:

> Is the resulting object code similar in size and performance to writing a  
> tail recursive loop? The implementation in the prelude looks like it might  
> have more overhead in terms of generated code, etc.

---

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [November 2, 2015, 12:41am UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/12 "2015-11-02T00:41:21Z")

</div>

Here is a metric from my code:

The original code used 13K of program space. By using templates everywhere,  
it increased size by 37% to 18K.

Given the Atmega328 has a 32K program space, this is pretty painful.

If functions in ATS require 2-3 C functions this may become a practical  
limit to use of ATS in very small embedded systems. So while the statics go  
away, the this overhead does not.

The non-template version is not limited by code speed, but by IO, most of  
the time. But different parts of the code have different needs. Given that  
some functions will be shared between time critical and space critical  
parts of the code, what is needed is a way to annotate the code to tell the  
ATS when to instantiate a template, and when to use a shared function.  
Thus, being able to use templates in time critical areas, and not in others

Given the above, is there a way to put a wrapper around each template such  
that when used, it uses a shared function, but does not add even more C  
function call overhead? The idea being a template is instantiated once as a  
shared function, with no additional overhead in the generated code, or at  
least a very small overhead like one pointer dereference, etc.

---

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [October 30, 2015, 1:13pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/13 "2015-10-30T13:13:02Z")

</div>

I see the point about full optimization, but now I have to consider that if  
I break a large application into multiple files, I have dependencies like:

A depends B == a -\> B

so

C -\> G  
D -\> G  
M -\> C && D

So there is then no way to get all the templates to expand in M (Main)

The same would happen when using a library in prelude or contrib in a  
multiple application.

Given that, if all functions in G are templates, and all functions in C and  
D are templates, will all the template expansions end up in M like you  
recommend?

If so, I can have my cake and eat it 🙂

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 29, 2015, 3:07pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/14 "2015-10-29T15:07:48Z")

</div>

You should be able to find proper compiler options to suppress such warning  
messages.

But there are a few programming style issues that I’d like to mention here.

Try to use templates extensively. Say you have foo1.dats, foo2.dats and  
main.dats.  
Usually, the idea is to have only templates inside foo1.dats and foo2.dats.  
In main.dats,  
you have

staload “foo1.dats”  
staload “foo2.dats”

Think of it this way: foo1.dats and foo2.dats are here to generate C code  
used in main.dats.

If there are functions in foo1.dats that are not templates, you can add the  
following code in  
main.dats:

local  
#include “foo1.dats”  
in (_nothing_) end

The idea is to generate only one file containing all the C code you want.  
In this way, gcc/clang  
can optimize to the fullest extent when compiling the generated C code.

I will talk about the ‘const’ issue in a separate message.On Thursday, October 29, 2015 at 9:58:05 AM UTC-4, Mike Jones wrote:

> My application has lots of warnings like shown below. Should I be trying  
> to remove these or are they typical of ATS application and to be ignored?  
> Are there some standard compiler flags that would turn off things that  
> should be ignored?
> 
> To take a particular case, the first error about const, I have the  
> following C declarations:
> 
> uint8\_t packetIn[127];  
> const uint8\_t \*packetInCount = packetIn;  
> const uint8\_t \*packetInHeader = packetIn + 1;
> 
> The idea being there are some pointers into a block of data that never  
> change.
> 
> And, I assume arrayref does some kind of implicit cast and then there is a  
> warning. Note, I am not a C compiler expert, so I’m doing some guessing  
> here.
> 
> DATS/frames\_dats.c: In function ‘process\_smbus\_frame\_command\_138’:  
> DATS/frames\_dats.c:9714:1: warning: passing argument 1 of  
> ‘ATSLIB\_056\_prelude\_\_arrayref\_get\_at\_gint\_\_20\_\_5’ discards ‘const’  
> qualifier from pointer target type [enabled by default]  
> ATSINSmove(tmp356,  
> ATSLIB\_056\_prelude\_\_arrayref\_get\_at\_gint\_\_20\_\_5(ATSPMVextval(packetInContents),  
> ATSPMVi0nt(0))) ;  
> ^  
> DATS/frames\_dats.c:861:1: note: expected ‘atstype\_ptrk’ but argument is of  
> type ‘const uint8\_t \*’  
> ATSLIB\_056\_prelude\_\_arrayref\_get\_at\_gint\_\_20\_\_5(atstkind\_type(atstype\_ptrk),  
> atstkind\_t0ype(atstype\_int)) ;  
> ^  
> patsopt -o DATS/main\_dats.c.tmp -d DATS/main.dats  
> mv DATS/main\_dats.c.tmp DATS/main\_dats.c  
> avr-gcc -g -Wall -O2 -mmcu=atmega328p -DF\_CPU=16000000UL -std=c99  
> -D\_XOPEN\_SOURCE -D\_ATSTYPE\_VAR\_SIZE\_=0X000F -D\_ATS\_CCOMP\_EXCEPTION\_NONE\_  
> -D\_ATS\_CCOMP\_RUNTIME\_NONE\_ -D\_ATS\_CCOMP\_PRELUDE\_NONE\_  
> -D\_ATS\_CCOMP\_PRELUDE\_USER\_="/home/mike/linti/libs/arduino-ats/avr\_prelude/kernel\_prelude.cats"  
> -Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable -I.  
> -I/opt/ATS/ATS2-Postiats-0.2.4 -I/opt/ATS/ATS2-Postiats-0.2.4/ccomp/runtime  
> -I/home/mike/linti/libs/arduino-ats/\_arduino  
> -I/home/mike/linti/libs/arduino-ats/\_dummy  
> -I/home/mike/linti/libs/arduino-ats -c -o DATS/main\_dats.o DATS/main\_dats.c  
> DATS/main\_dats.c:333:1: warning: ‘output\_high\_1’ defined but not used  
> [-Wunused-function]  
> output\_high\_1(atstkind\_t0ype(atstype\_int) arg0)  
> ^  
> DATS/main\_dats.c:363:1: warning: ‘input\_2’ defined but not used  
> [-Wunused-function]  
> input\_2(atstkind\_t0ype(atstype\_int) arg0)

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [November 3, 2015, 2:47am UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/15 "2015-11-03T02:47:25Z")

</div>

> > with possible throwing of exceptions for the unimplemented.

This happens at compile-time (after typechecking).

Currently, a failed template instantiation results in  
a message (issued by the C compiler) that reads like:

error: ‘PMVtmpltcstmat’ undeclaredOn Mon, Nov 2, 2015 at 9:34 PM, Mike Jones [proc...@gmail.com](mailto:proc...@gmail.com) wrote:

> The template approach will allow more or lesser number of functions rather  
> than requiring a fixed interface, with possible throwing of exceptions for  
> the unimplemented. This does have merit, so I will give this a go.
> 
> The Haskell approach was in reaction to several attempts that failed in  
> one way or another and this was the best of multiple alternatives. I’m not  
> stuck on it if there is a better approach.
> 
> –  
> 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](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/22ec2ecc-a734-41d5-a4c2-532da0ea861a%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/22ec2ecc-a734-41d5-a4c2-532da0ea861a%40googlegroups.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/22ec2ecc-a734-41d5-a4c2-532da0ea861a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/22ec2ecc-a734-41d5-a4c2-532da0ea861a%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [November 2, 2015, 4:22pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/16 "2015-11-02T16:22:51Z")

</div>

Well, the point of using a template-based approach is to obviate the need  
for building closures. If closures had to be built at run-time, then I  
would use  
higher-order functions (instead of templates).On Mon, Nov 2, 2015 at 10:17 AM, Mike Jones [proc...@gmail.com](mailto:proc...@gmail.com) wrote:

> I think that ultimately, a closure is required to capture a moniker used  
> by an implementation of an interface, to do what the Haskell example does.
> 
> –  
> 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](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/b22afdfb-6dea-483d-9ab7-99ead6243fa0%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/b22afdfb-6dea-483d-9ab7-99ead6243fa0%40googlegroups.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/b22afdfb-6dea-483d-9ab7-99ead6243fa0%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/b22afdfb-6dea-483d-9ab7-99ead6243fa0%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .

---

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [November 2, 2015, 3:14pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/17 "2015-11-02T15:14:56Z")

</div>

So, I assume there will be one implement statement for each bus type? If  
not, then the the structure of the code has to be the same for all passed  
in types, like the way templates work in C++ where the passed in type, say  
int or double, has operators that work for both. In the SMBus case, the  
interfaces to the lower SMBus layer, say Aardvark vs. other hardware, may  
have significant differences so there needs to be one implementation for  
each one.

The next issue is how to call. The Haskell solution has one statement that  
picks the type of hardware, then the code is the same. In the template  
case, how do you do that?

If the function has to be called as sendByte(0x30, 0x01, err) then  
there will be conditionals everywhere, because the call has to give the  
type.

Is there a simple way to pick the instance, and call as sendByte(0x30,  
0x01, err)?

The final problem is the instance has to capture a handle, which is  
returned from an IO call. Templates are instantiated at compile time, not  
run time, so I don’t think they can capture the value. Which leads me to  
believe I will still have to pass a moniker to every call.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 29, 2015, 5:58pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/18 "2015-10-29T17:58:14Z")

</div>

The ‘const’ qualifier in C has no counterpart in ATS  
for the moment.

In any case, exporting global variables in C for use in ATS  
can and should probably be avoided. For instance, you example  
may be done as follows:

%{^  
//  
uint8\_t packetIn[127];  
const uint8\_t \*packetInCount = packetIn;  
const uint8\_t \*packetInHeader = packetIn + 1;  
//  
#define packetInCount\_get() (packetInCount[0])  
#define packetInHeader\_get\_at(i) (packetInHeader[i])  
//  
%}

extern  
fun packetInCount\_get(): uint8 = “mac#”  
extern  
fun packetInHeader\_get\_at(natLt(126)): uint8 = "mac#"On Thursday, October 29, 2015 at 9:58:05 AM UTC-4, Mike Jones wrote:

> My application has lots of warnings like shown below. Should I be trying  
> to remove these or are they typical of ATS application and to be ignored?  
> Are there some standard compiler flags that would turn off things that  
> should be ignored?
> 
> To take a particular case, the first error about const, I have the  
> following C declarations:
> 
> uint8\_t packetIn[127];  
> const uint8\_t \*packetInCount = packetIn;  
> const uint8\_t \*packetInHeader = packetIn + 1;
> 
> The idea being there are some pointers into a block of data that never  
> change.
> 
> And, I assume arrayref does some kind of implicit cast and then there is a  
> warning. Note, I am not a C compiler expert, so I’m doing some guessing  
> here.
> 
> DATS/frames\_dats.c: In function ‘process\_smbus\_frame\_command\_138’:  
> DATS/frames\_dats.c:9714:1: warning: passing argument 1 of  
> ‘ATSLIB\_056\_prelude\_\_arrayref\_get\_at\_gint\_\_20\_\_5’ discards ‘const’  
> qualifier from pointer target type [enabled by default]  
> ATSINSmove(tmp356,  
> ATSLIB\_056\_prelude\_\_arrayref\_get\_at\_gint\_\_20\_\_5(ATSPMVextval(packetInContents),  
> ATSPMVi0nt(0))) ;  
> ^  
> DATS/frames\_dats.c:861:1: note: expected ‘atstype\_ptrk’ but argument is of  
> type ‘const uint8\_t \*’  
> ATSLIB\_056\_prelude\_\_arrayref\_get\_at\_gint\_\_20\_\_5(atstkind\_type(atstype\_ptrk),  
> atstkind\_t0ype(atstype\_int)) ;  
> ^  
> patsopt -o DATS/main\_dats.c.tmp -d DATS/main.dats  
> mv DATS/main\_dats.c.tmp DATS/main\_dats.c  
> avr-gcc -g -Wall -O2 -mmcu=atmega328p -DF\_CPU=16000000UL -std=c99  
> -D\_XOPEN\_SOURCE -D\_ATSTYPE\_VAR\_SIZE\_=0X000F -D\_ATS\_CCOMP\_EXCEPTION\_NONE\_  
> -D\_ATS\_CCOMP\_RUNTIME\_NONE\_ -D\_ATS\_CCOMP\_PRELUDE\_NONE\_  
> -D\_ATS\_CCOMP\_PRELUDE\_USER\_="/home/mike/linti/libs/arduino-ats/avr\_prelude/kernel\_prelude.cats"  
> -Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable -I.  
> -I/opt/ATS/ATS2-Postiats-0.2.4 -I/opt/ATS/ATS2-Postiats-0.2.4/ccomp/runtime  
> -I/home/mike/linti/libs/arduino-ats/\_arduino  
> -I/home/mike/linti/libs/arduino-ats/\_dummy  
> -I/home/mike/linti/libs/arduino-ats -c -o DATS/main\_dats.o DATS/main\_dats.c  
> DATS/main\_dats.c:333:1: warning: ‘output\_high\_1’ defined but not used  
> [-Wunused-function]  
> output\_high\_1(atstkind\_t0ype(atstype\_int) arg0)  
> ^  
> DATS/main\_dats.c:363:1: warning: ‘input\_2’ defined but not used  
> [-Wunused-function]  
> input\_2(atstkind\_t0ype(atstype\_int) arg0)

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [November 2, 2015, 6:01am UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/19 "2015-11-02T06:01:03Z")

</div>

ATS supports currying. It is just that currying is of little use in ATS as  
ATS already supports functions of multiple arguments.

Instead of writing ‘foo(x)(y)’, you write foo(x, y); so ‘foo(x)’ is lam(x)  
=\> foo(x, y).

Returning a closure-function without malloc means the caller needs to  
provide memory  
for storing the returned closure-function; often the memory is in the frame  
of the caller.

> > The example I am thinking of is opening a handle, and hiding it in a data  
> > type of lambdas, where the datatype is like an interface, and an open  
> > function returns the datatype with the handle hidden.

Using closure to hide information is rather awkward:

[http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/HTMLTOC/x1509.html](http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/HTMLTOC/x1509.html)

I would suggest using abstract types to hide information. If you can  
provide some pseudo code, I will have  
a better idea about what you said above.On Mon, Nov 2, 2015 at 12:23 AM, Mike Jones [proc...@gmail.com](mailto:proc...@gmail.com) wrote:

> ATS does not allow currying, correct?
> 
> The most you can do is capture a value from the outer context I think. But  
> if a lambda does capture a value, can you return the lambda from a function  
> without boxing/malloc? That would allow making a creator function that  
> returns curried functions. Even better if you can return them in a datatype.
> 
> The example I am thinking of is opening a handle, and hiding it in a data  
> type of lambdas, where the datatype is like an interface, and an open  
> function returns the datatype with the handle hidden.
> 
> This would reuse context and make the code faster because the handle does  
> not need to be passed on every function call. In a loop context, the lambda  
> could be used with a map, fold, etc.
> 
> –  
> 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](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/a49d73cf-e3d8-46c9-81c7-f26563754032%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/a49d73cf-e3d8-46c9-81c7-f26563754032%40googlegroups.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/a49d73cf-e3d8-46c9-81c7-f26563754032%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/a49d73cf-e3d8-46c9-81c7-f26563754032%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [October 30, 2015, 1:21pm UTC](https://discourse.ats-lang.org/t/compiler-warnings/715/20 "2015-10-30T13:21:50Z")

</div>

I just want to add that you can actually have a situation where

C depends on D and D depends on C.

Mutual dependency is not a problem as far as template instantiation is of  
the concern.On Friday, October 30, 2015 at 9:19:22 AM UTC-4, gmhwxi wrote:

> > > Given that, if all functions in G are templates, and all functions in C  
> > > and D are templates, will all the template expansions end up in M like you  
> > > recommend?
> 
> Yes, all the template expansions end up in M as can be expected.
> 
> > > If so, I can have my cake and eat it 🙂
> 
> Yes, both 🙂
> 
> By the way, the ‘and’ in the above sentence is linear (as in linear logic).
> 
> On Friday, October 30, 2015 at 9:13:02 AM UTC-4, Mike Jones wrote:
> 
> > I see the point about full optimization, but now I have to consider that  
> > if I break a large application into multiple files, I have dependencies  
> > like:
> > 
> > A depends B == a → B
> > 
> > so
> > 
> > C → G  
> > D → G  
> > M → C && D
> > 
> > So there is then no way to get all the templates to expand in M (Main)
> > 
> > The same would happen when using a library in prelude or contrib in a  
> > multiple application.
> > 
> > Given that, if all functions in G are templates, and all functions in C  
> > and D are templates, will all the template expansions end up in M like you  
> > recommend?
> > 
> > If so, I can have my cake and eat it 🙂

[Next page](https://discourse.ats-lang.org/t/compiler-warnings/715.md?page=2)
