Thread: [ats-lang-users] New to ATS
Unleashing the potentials of types and templates
Status: Beta
Brought to you by:
ats-hwxi
From: Rouan v. D. <rv...@ya...> - 2010-03-14 06:09:36
|
Hi everyone. I have stumbled onto ATS because I am interrested in non-main stream programming languages and love to try out interresting ones. As I have no experience in ATS and I can't find too many blogs about it, I have a few questions. 1. Would you say that ATS is ready for writing applications outside the academic environment? 2. How expressive is its type-system, compared to say OCaml / Haskell? ATS seems like a language where I can write in a functional style (which I really like) and it seems that ATS can be used to write fairly efficient code. I am looking to invest some substantial time into ATS if I can use it for more practical, real-world programming. I am looking for a good, efficient language to write a compiler for my own programming language. I am hoping that ATS will be this language. Can anyone advise if ATS is a good language for this purpose and if there are any specific features of ATS that would come in handy for writing a compiler in ATS. Regards Rouan |
From: Hongwei Xi <hw...@cs...> - 2010-03-14 16:03:28
|
On Sun, 14 Mar 2010, Rouan van Dalen wrote: >>Hi everyone. >> >>I have stumbled onto ATS because I am interrested in non-main stream programming languages and love to try >>out interresting ones. >> >>As I have no experience in ATS and I can't find too many blogs about it, I have a few questions. Good. Let me try to address your questions. Given that I am the principal designer and implementer of ATS, I have to say that I am a bit biased :) >>1. Would you say that ATS is ready for writing applications outside the academic environment? Yes! So far, the largest software written in ATS is ATS/Anairiats, the current compiler for ATS. It consists of more than 90K lines of code. Given that ATS uses native data representation as C, it is straightforward to port C library to ATS. Given that ATS code is compiled to C first, linking with C library code is a no-brainer. I myself even use ATS for scripting, graphics, slide presentation, etc. I see no problem at all writing real applications in ATS. >>2. How expressive is its type-system, compared to say OCaml / Haskell? A great deal more expressive. It is hard to quantify this. The very strength of ATS is in its type system. It may take years of learning for one to truly unleash the power of the types in ATS (it takes a lot of time for one to use C++ effectively, too :)) >>ATS seems like a language where I can write in a functional style (which I really like) and it seems >>that ATS can be used to write fairly efficient code. >> >>I am looking to invest some substantial time into ATS if I can use it for more practical, real-world >>programming. I have never worked in the industry, so I don't really have a clear idea as to what a real-world application looks like. However, I have read a lot of open-source code, and can easily imagine to implement such code in ATS; actually, I can often easily imagine to do a better implementation in ATS by taking advantage of the type system of ATS. >>I am looking for a good, efficient language to write a compiler for my own programming language. >>I am hoping that ATS will be this language. Can anyone advise if ATS is a good language for >>this purpose and if there are any specific features of ATS that would come in handy for writing >>a compiler in ATS. It is hard to say because I don't know what your language is like. In general, writing a compiler in ATS is most like writing a compiler in a language like ocaml. However, you can certainly do more verification by making use of dependent types and linear types in ATS. If you need, I will be happy to point to you some resources for writing a compiler in ATS. If you have further questions, I will be happy to address (to the extent I can). --Hongwei Computer Science Department Boston University 111 Cummington Street Boston, MA 02215 Email: hw...@cs... Url: http://www.cs.bu.edu/~hwxi Tel: +1 617 358 2511 (office) Fax: +1 617 353 6457 (department) |
From: Rouan v. D. <rv...@ya...> - 2010-03-15 07:49:40
|
Hi Thanks for the replies. Its great to hear that ATS is stable enough for real-world applications :) I don't mind spending time learning ATS and how to effectively use its types. I have the most experience in C/C++/Haskell/OCaml/C#/F#. I like static typing and having a type system to verify that my programs are sane at some level at least. This should give you an idea of the type of type-systems that I am used to. It is my first time hearing of dependent and linear types and I don't yet know what the advantages are of having them in a language. If possible, could anyone give / point me to small code samples that are relatively easy to understand, highlighting the advantages of linear and dependent types. I do not have a solid background in type-theory / lambda-calc and im not looking to write proofs for programs. I want to write practical applications that work and if the language has some facilities to help with writing small proofs to increase the safety of the code I will use them, but sparingly. At least until I understand the ideas behind dependent types and proofs better :) That said, I am very interested in type systems and love learning these concepts so I am eager to learn from smart people. When I say real-world apps, I mean applications that solve practical problems (networking, GUI apps, compilers) instead of writing something like a proof for an algorithm (more academic stuff). Mixing C and ATS is really attractive to me and the programming language I am designing takes most of its inspiration from Haskell & OCaml, and will thus have a similar syntactic feel & feature set. I also intend to first compile down to C and then let the C compiler generate executable code. So if I have a language that gives me good access to C for writing bindings, etc. it will be a plus. One thing attracts me to ATS is the claim that you can still use low-level concepts like pointers, etc. (which are usually labelled unsafe) to write efficient code, but still have the compiler verify the safety. Hongwei, in your last email, you said that tupples should be used sparingly in ATS, is this correct? I use tuples a lot in my functional code in Haskell/OCaml and would like to know why I should rather use call-by-ref than tuples in ATS? Tupples are a very useful feature for me in the code I intend to write for my compiler. My ATS code would look like ML code at the start I suppose :) Does ATS support currying? I haven't found any indication in the available documentation. Thanks for all the patience Regards, Rouan. |
From: Likai L. <li...@cs...> - 2010-03-14 21:48:40
|
ATS differs from ML most notably: 1. You'll be writing a lot of type annotations. The amount you write depends on how you declared the type definition. The more precisely you specify the code's behavior through types, the better the ATS compiler can help you verify correctness. However, it takes a few years of experience to know exactly how much you need to write. Overdoing it will certainly make it a frustrating learning experience. It can be a real productivity killer. For now, you may start annotating ML-styled code in ATS, and it is just like ML. 2. ATS doesn't have a nice module system like ML does; there is no functor support. But the #include trick often used in C also works in ATS. 3. To start taking advantage of advanced ATS features like flat types (t@ype with a funky @), stack allocated storage, and linear views, you might want to consider writing functional-styled programs in C first, then you'd come to appreciate it better. GCC can do tail call optimization in C/C++, although ATS does its own tail call before generating C code. Also, I'm not sure whether the efficiency of the host language really matters for writing a compiler. I thought the code your compiler generates would be more important. You could probably start prototyping in O'Caml and Haskell and rewrite in ATS later. As long as you stay within the confines of mini ML, the port should be easy. liulk On Sun, Mar 14, 2010 at 2:09 AM, Rouan van Dalen <rv...@ya...> wrote: > Hi everyone. > > > I have stumbled onto ATS because I am interrested in non-main stream programming languages and love to try > out interresting ones. > > As I have no experience in ATS and I can't find too many blogs about it, I have a few questions. > > 1. Would you say that ATS is ready for writing applications outside the academic environment? > > 2. How expressive is its type-system, compared to say OCaml / Haskell? > > ATS seems like a language where I can write in a functional style (which I really like) and it seems > that ATS can be used to write fairly efficient code. > > I am looking to invest some substantial time into ATS if I can use it for more practical, real-world > programming. > > I am looking for a good, efficient language to write a compiler for my own programming language. > I am hoping that ATS will be this language. Can anyone advise if ATS is a good language for > this purpose and if there are any specific features of ATS that would come in handy for writing > a compiler in ATS. > > > Regards > > Rouan |
From: Hongwei Xi <hw...@cs...> - 2010-04-05 11:03:07
|
On Mon, 5 Apr 2010, Rouan van Dalen wrote: >>Hi Hongwei >> >>I was wondering why ATS has template functions AND polymorphic functions? >> >>Where would I rather use a template than a polymorphic function? Say you have the following function: fun f {a:type} (x: a): a = x 'f' is polymorphic. However, 'f' can only be applied to a boxed value. E.g., f(0.0) results in a type error as 'double' is not a boxed type. BTW, all datatypes are boxed. Suppose we implement f as follows: fun f {a:t@ype} (x: a): a = x Unfortuately, this function cannot be compiled as the size of 'a' is unknown at compile-time. In ATS, 'f' can be implemented as follows: fun{a:t@ype} f (x: a): a = x This is a function template. Just like in C++, a template is not compiled until it is applied. If you call f(1), then *essentially*, the following function is generated fun f_int (x: int): x = x and the call becomes f_int(1). If you call f(1.0), then the following function is generated: fun f_double (x: int): x = x and the call becomes f_double(1.0). In pratice, I find templates to be extremely useful, especially, when implementing library code. Hope this helps, --Hongwei Computer Science Department Boston University 111 Cummington Street Boston, MA 02215 Email: hw...@cs... Url: http://www.cs.bu.edu/~hwxi Tel: +1 617 358 2511 (office) Fax: +1 617 353 6457 (department) |
From: Matthias B. <mat...@gm...> - 2010-04-05 11:29:40
|
> This is a function template. Just like in C++, a template is not > compiled until it is applied. If you call f(1), then *essentially*, > the following function is generated > > fun f_int (x: int): x = x That should probably be fun f_int(x: int): int = x > and the call becomes f_int(1). If you call f(1.0), then the following > function is generated: > > fun f_double (x: int): x = x And this should probably be fun f_double(x: double): double = x |
From: Hongwei Xi <hw...@cs...> - 2010-04-11 10:34:13
|
On Sun, 11 Apr 2010, Rouan van Dalen wrote: >>Hi Hongwei >> >>Is there an int_of_float function in ATS? >> >>If so, do I need to include anything special to use it? >>If not, what would I need to do to convert a float value to an integer? Yes, there is one. It is in prelude/SATS/float.sats You can also do something as follows to implement such a function in C and then use it in ATS: %{^ static inline ats_int_type int_of_float (ats_float_type x) { return x ; } %} extern fun int_of_float (x: float): int = "int_of_float" Or you can introduce a casting function in ATS as follows: extern castfn int_of_float (x: float): int Cheers, --Hongwei Computer Science Department Boston University 111 Cummington Street Boston, MA 02215 Email: hw...@cs... Url: http://www.cs.bu.edu/~hwxi Tel: +1 617 358 2511 (office) Fax: +1 617 353 6457 (department) |