Re: Arrays, lists, and records

2017-10-22 Thread gmhwxi

Unfortunately, this is not currently supported in ATS.

You need to go through C in order to create a value of type suite(a, n):

%{^
typedef
struct {
  void *name,
  void *setup,
  void *teardown,
  void *tests[0]
} suite;
%}

typedef
suite(data:t0ype,n:int) =
$extype_struct "suite" of { 
  
  name = string,   
  
  setup = (data -> void),   
  
  teardown = (data -> void),   
  
  tests = @[test][n]  
}



On Sunday, October 22, 2017 at 6:34:08 PM UTC-4, Andrew Knapp wrote:
>
> I'd like to write something like the following code:
>
> #include "share/atspre_staload.hats"
> #include "share/atspre_define.hats"
>
> typedef test = () -> int(* better type later *)
>
> typedef suite(data:t0ype,n:int) = @{
>   name = string,
>   setup = (data -> void),
>   teardown = (data -> void),
>   tests = @[test][n]
> }
>
> fun foo_setup(a:int): void = println!("setting up")
> fun foo_teardown(a:int): void = println!("tearing down")
>
> fun baz(): int =
> let
>   val () = println!("baz")
> in
>   3
> end
>
> fun bar(): int =
> let
>   val () = println!("bar")
> in
>   4
> end
>
> var foo_tests = @[test][2](bar, baz)
>
> val foo : suite(int,2) = @{
>   name = "hello world",
>   setup = foo_setup,
>   teardown = foo_teardown,
>   tests = foo_tests
> }
>
> implement main0() =
> let
> in
>   println!("Hello, world!")
> end
>
> but the C compiler fails with these errors
>
> modules_dats.c:262:1: warning: parameter names (without types) in function 
> declaration
>  atstype_funptr atstyarr_field(atslab__tests) ;
>  ^~
> In file included from modules_dats.c:14:0:
> /usr/lib/ats2-postiats-0.3.7/ccomp/runtime/pats_ccomp_typedefs.h:176:31: 
> error: field ‘atstyarr_field_undef’ declared as a function
>  #define atstyarr_field(fname) atstyarr_field_undef(fname)
>^
> modules_dats.c:262:16: note: in expansion of macro ‘atstyarr_field’
>  atstype_funptr atstyarr_field(atslab__tests) ;
> ^~
> modules_dats.c:269:1: warning: parameter names (without types) in function 
> declaration
>  atstype_funptr atstyarr_field(atslab__tests) ;
>  ^~
> In file included from modules_dats.c:14:0:
> /usr/lib/ats2-postiats-0.3.7/ccomp/runtime/pats_ccomp_typedefs.h:176:31: 
> error: field ‘atstyarr_field_undef’ declared as a function
>  #define atstyarr_field(fname) atstyarr_field_undef(fname)
>^
> modules_dats.c:269:16: note: in expansion of macro ‘atstyarr_field’
>  atstype_funptr atstyarr_field(atslab__tests) ;
> ^~
> In file included from modules_dats.c:15:0:
> modules_dats.c: In function ‘
> _057_home_057_andy_057_tmp_057_modules_057_modules_056_dats__dynload’:
> modules_dats.c:623:52: error: ‘postiats_tyrec_0 {aka struct }’ 
> has no member named ‘atslab__tests’; did you mean ‘atslab__setup’?
>  ATSINSstore_fltrec_ofs(statmp12, postiats_tyrec_1, atslab__tests, 
> statmpref10) ;
> ^
> /usr/lib/ats2-postiats-0.3.7/ccomp/runtime/pats_ccomp_instrset.h:321:61: 
> note: in definition of macro ‘ATSINSstore_fltrec_ofs’
>  #define ATSINSstore_fltrec_ofs(tmp, tyrec, lab, val) ((tmp).lab = val)
>  ^~
>
> I would use viewtype lists instead of arrays, but the compiler complains 
> about requiring fields to be of sort t0ype, not viewt0ype.
>
> Thanks,
> Andrew
>

-- 
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/8c7945d7-bd13-48aa-9b14-2002cfc17c30%40googlegroups.com.


Arrays, lists, and records

2017-10-22 Thread Andrew Knapp
I'd like to write something like the following code:

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

typedef test = () -> int(* better type later *)

typedef suite(data:t0ype,n:int) = @{
  name = string,
  setup = (data -> void),
  teardown = (data -> void),
  tests = @[test][n]
}

fun foo_setup(a:int): void = println!("setting up")
fun foo_teardown(a:int): void = println!("tearing down")

fun baz(): int =
let
  val () = println!("baz")
in
  3
end

fun bar(): int =
let
  val () = println!("bar")
in
  4
end

var foo_tests = @[test][2](bar, baz)
   
val foo : suite(int,2) = @{
  name = "hello world",
  setup = foo_setup,
  teardown = foo_teardown,
  tests = foo_tests
}

implement main0() =
let
in
  println!("Hello, world!")
end

but the C compiler fails with these errors

modules_dats.c:262:1: warning: parameter names (without types) in function 
declaration
 atstype_funptr atstyarr_field(atslab__tests) ;
 ^~
In file included from modules_dats.c:14:0:
/usr/lib/ats2-postiats-0.3.7/ccomp/runtime/pats_ccomp_typedefs.h:176:31: 
error: field ‘atstyarr_field_undef’ declared as a function
 #define atstyarr_field(fname) atstyarr_field_undef(fname)
   ^
modules_dats.c:262:16: note: in expansion of macro ‘atstyarr_field’
 atstype_funptr atstyarr_field(atslab__tests) ;
^~
modules_dats.c:269:1: warning: parameter names (without types) in function 
declaration
 atstype_funptr atstyarr_field(atslab__tests) ;
 ^~
In file included from modules_dats.c:14:0:
/usr/lib/ats2-postiats-0.3.7/ccomp/runtime/pats_ccomp_typedefs.h:176:31: 
error: field ‘atstyarr_field_undef’ declared as a function
 #define atstyarr_field(fname) atstyarr_field_undef(fname)
   ^
modules_dats.c:269:16: note: in expansion of macro ‘atstyarr_field’
 atstype_funptr atstyarr_field(atslab__tests) ;
^~
In file included from modules_dats.c:15:0:
modules_dats.c: In function ‘
_057_home_057_andy_057_tmp_057_modules_057_modules_056_dats__dynload’:
modules_dats.c:623:52: error: ‘postiats_tyrec_0 {aka struct }’ 
has no member named ‘atslab__tests’; did you mean ‘atslab__setup’?
 ATSINSstore_fltrec_ofs(statmp12, postiats_tyrec_1, atslab__tests, 
statmpref10) ;
^
/usr/lib/ats2-postiats-0.3.7/ccomp/runtime/pats_ccomp_instrset.h:321:61: 
note: in definition of macro ‘ATSINSstore_fltrec_ofs’
 #define ATSINSstore_fltrec_ofs(tmp, tyrec, lab, val) ((tmp).lab = val)
 ^~

I would use viewtype lists instead of arrays, but the compiler complains 
about requiring fields to be of sort t0ype, not viewt0ype.

Thanks,
Andrew

-- 
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/c2552f4f-8c9a-45b3-9847-53740f4abeb6%40googlegroups.com.


Re: Static Templates

2017-10-22 Thread Steinway Wu
I was trying to add some "derive" functionality by representing datatypes, 
say "a" with some generic datatype, say "rep (a)". However, for a generic 
function to work on a value of type "rep (a)", we need the type information 
for the actual values stored in the original value of type "a" (which are 
copied into the value of type "rep (a)"). 

It's much like trying to print a heterogeneous list, generically. I need to 
supply the print function with the actual type of every element. Thus I 
think I probably need the type info to be a template, so that the user can 
instantiate it for every datatype they want to be generic. 

Am I on the right track? Are there other ways of doing it? 

On Saturday, October 21, 2017 at 4:26:02 PM UTC-4, gmhwxi wrote:
>
> I don't know how to do it,
>
> This gets into the domain of meta-programming.
>
> In general, it is very difficult to do meta-programming in a typeful
> manner.  Often one tries to write code to generate code that may
> contain type-error and then apply typechecking to the generated code.
>
> On Friday, October 20, 2017 at 5:45:45 PM UTC-4, Steinway Wu wrote:
>>
>> Hi, 
>>
>> We now have dynamic templates, parameterized by static terms. Is it 
>> possible to have some simple form of static templates like the followings? 
>> Or is there any other way to make static functions ad-hoc polymorphic? 
>>
>> datasort typelist =
>> | tnil of ()
>> | tcons of (t@ype, typelist)
>>
>> #define :: tcons
>>
>> datatype OneConstructor = One of (int, int, string)
>> datatype AnotherConstructor = Another of (int, int, bool)
>>
>> template stacst Code: typelist
>>
>> implement Code = int :: int :: string :: tnil
>> implement Code = int :: int :: bool :: tnil
>>
>>
>>
>>
>>
>>
>>

-- 
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/94b5a0fb-1f06-4f47-adb3-ab1ccb464ae7%40googlegroups.com.