Redefining function template

29 views
Skip to first unread message

Mike Jones

unread,
Nov 25, 2015, 10:37:49 AM11/25/15
to ats-lang-users
This code gives compile error:

mike: 4385(line=147, offs=36) -- 4406(line=147, offs=57): error(3): the dynamic expression cannot be assigned the type [S2Efun(FUN; lin=0; eff=S2EFFset(1); npf=-1; S2Ecst(hex_t), S2Ecst(hex_t); S2Ecst(uint8))].
mike: 4385(line=147, offs=36) -- 4406(line=147, offs=57): error(3): mismatch of static terms (tyleq):
The actual term is: S2Eapp(S2Ecst(g0uint_t0ype); S2Eextkind(atstype_uint8))
The needed term is: S2Efun(FUN; lin=0; eff=S2EFFset(1); npf=-1; S2Ecst(hex_t), S2Ecst(hex_t); S2Ecst(uint8))
patsopt(TRANS3): there are [1] errors in total.
exit(ATS): uncaught exception: _2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)


Which I think means hex_to_byte_ is not returning a function type. I have a similar one without parameters that works, but I am not sure how to structure this code so that it works with parameters. The goal being to instantiate the template so I can effectively turn it off to make inlining tradeoffs. In the present case, compiling for my Cypress A9 target in debug mode is exploding the size of the code and there is not enough memory. I suppose I could also tell the compiler not to inline, but let's see if I can make this work for the more general case.

extern fun{} hex_to_byte (msn: hex_t, lsn: hex_t) : uint8
implement{} hex_to_byte (msn, lsn) = let
 ...
in
  ...
end

extern fun hex_to_byte_(msn: hex_t, lsn: hex_t) : $d2ctype(hex_to_byte<>)
implement hex_to_byte_(msn, lsn) = hex_to_byte(msn, lsn)

#define hex_to_byte hex_to_byte_


Hongwei Xi

unread,
Nov 25, 2015, 10:42:19 AM11/25/15
to ats-lan...@googlegroups.com

>>extern fun hex_to_byte_(msn: hex_t, lsn: hex_t) : $d2ctype(hex_to_byte<>)

Should be

extern fun hex_to_byte_ : $d2ctype(hex_to_byte<>)

--
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 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/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com.

Mike Jones

unread,
Nov 25, 2015, 11:52:33 AM11/25/15
to ats-lang-users
I had that originally, but failed in the C compile. It turned out that I needed: staload _ = "prelude/DATS/integer_fixed.dats"

It seems that this staload is required in the file that instantiates the template, not the file that defines it. Furthermore, it appears that staload of dats file is recursive, because this load was not in the original file that instantiated. It had to pick it up from some other load.

Is there some easy way such that if you staload load a dats file the proper staload dependencies come with it, and the compiler checks that you have them in the file defining the template so that anyone that reuses your code does not have to struggle to find the missing staload for its templates?

Mike Jones

unread,
Nov 25, 2015, 12:40:52 PM11/25/15
to ats-lang-users
This one is causing problems with g0uint_t0ype and array_get_at_gint in terms of missing casts, and including unsafe.sats/dats and basics_sta.sats are not fixing it, even though they are defined in these. Do I need to change the second implement somehow? Perhaps to account for the existential?


extern fun{} set_n {n0: nat | n0 >= 3 && n0 <= 127} (count: int(n0)): void
implement{} set_n {n0} (count) = let
 ..
in 
  ...
end

extern
fun set_n_ : $d2ctype(set_n<>)
implement set_n_(count) = set_n(count)

#define set_n set_n_


Mike Jones

unread,
Nov 25, 2015, 1:01:51 PM11/25/15
to ats-lang-users
I solved another instantiation problem, and the one magically disappeared. I don't know why, but I'm moving forward.

gmhwxi

unread,
Nov 25, 2015, 5:16:41 PM11/25/15
to ats-lang-users


On Wednesday, November 25, 2015 at 11:52:33 AM UTC-5, Mike Jones wrote:
I had that originally, but failed in the C compile. It turned out that I needed: staload _ = "prelude/DATS/integer_fixed.dats"

It seems that this staload is required in the file that instantiates the template, not the file that defines it. Furthermore, it appears that staload of dats file is recursive, because this load was not in the original file that instantiated. It had to pick it up from some other load.

Is there some easy way such that if you staload load a dats file the proper staload dependencies come with it, and the compiler checks that you have them in the file defining the template so that anyone that reuses your code does not have to struggle to find the missing staload for its templates?

There is no such an easy way right now.

Reply all
Reply to author
Forward
0 new messages