I want to create abstract types such that ...

60 views
Skip to first unread message

chotu s

unread,
Mar 1, 2014, 2:34:02 AM3/1/14
to ats-lan...@googlegroups.com
I want to create two abstract type say T1,T2 . I also want some relationship between T1 and T2 say I want that T2 is a subtype of T1 i.e T2 <= T1

Finally I want a function of one argument that takes a not only of type T1 , but also all subtypes of T1 which includes T2.

Is it possible to create such type hierarchy in ATS ?

I know I can use t@ype+ , but I'll like to see full example if possible.


Thanks.

gmhwxi

unread,
Mar 1, 2014, 11:58:03 AM3/1/14
to ats-lan...@googlegroups.com
Yes, you can.

This sounds like a class hierarchy.

Take a look at

ATSCNTRB/contrib/GTK for examples using classdec.

chotu s

unread,
Mar 2, 2014, 10:29:30 AM3/2/14
to gmhwxi, ats-lan...@googlegroups.com
My prev post was lost , so apology if you get double posting

So I did take a quick look at gtk sat files , and managed to use classdec in a program successfully.

A code using classdec that I tried(which compiles successfully) :

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

classdec CAT1
classdec CAT2 : CAT1
classdec CAT3


abstype AT1 ( c : cls) = ptr

stadef C1 = CAT1
typedef C1 = [c : cls | c <= C1] AT1 (c)

stadef C2 = CAT2
typedef C2 = [c : cls | c <= C2] AT1 (c)

 
extern
fun make_c1 () : AT1 (CAT1) = "mac#"

extern
fun make_c2 () : AT1 (CAT2) = "mac#" //C2


(* extern *)
(* fun take_c1 {c:cls | c <= CAT1} (pc : AT1 (c) ) : void *)
(* extern *)
(* fun take_c2 {c:cls | c <= CAT2} (pc : AT1 (c) ) : void *)


extern
fun take_c1  (pc : C1 ) : void = "mac#"
extern
fun take_c2  (pc : C2 ) : void = "mac#"


implement main0 () = {
   val c1 = make_c1 ()
   val c2 = make_c2 ()
   val () = take_c1 (c1)
   val () = take_c1 (c2)
   val () = take_c2 (c2)
   (* val () = take_c2 (c1) *) //this should not work if we uncomment it
}



I also used classes in datatype  which was interesting .  I'll try to program little more of it to understand it better

Thanks


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/def66e19-e975-4c75-8826-1c25d5b9e477%40googlegroups.com.

gmhwxi

unread,
Mar 2, 2014, 11:09:58 AM3/2/14
to ats-lan...@googlegroups.com
Good for you!

This feature (classdec) is primarily for building API for an external package (e.g., GTK)
written in a OOP style. ATS itself does have direct support for OOP.


On Saturday, March 1, 2014 2:34:02 AM UTC-5, chotu s wrote:
Reply all
Reply to author
Forward
0 new messages