Re: [Caml-list] Dependent types ?

2011-09-27 Thread Jocelyn Sérot
Le 26 sept. 11 à 18:44, Gabriel Scherer a écrit : Phantom types could be a solution but we must declare a new type for each possible size, which is cumbersome / annoying. If you define the type system yourself, you can easily add a family of type constants `sizen` (with `n` an integer

Re: [Caml-list] Dependent types ?

2011-09-27 Thread Jocelyn Sérot
Le 26 sept. 11 à 14:45, Yaron Minsky a écrit : As written, the behavior of the types might not be what you expect, since addition of two 16 bit ints may result in an int that requires 17 bits. In the current situation, this will be handled at the VHDL level. Making it explicit at CAPH

Re: [Caml-list] Dependent types ?

2011-09-27 Thread Jocelyn Sérot
You're perfectly right Christophe, I now realize that i've opened some kind of Pandora box. Supporting function declaration concat : intn - intm - intn+m (or multiplication) would be great (even with only addition on sizes), but a too long term goal for me (esp. taking into account that

Re: [Caml-list] Dependent types ?

2011-09-27 Thread Arnaud Spiwack
Yes, this is right. You can already experiment in ocaml, as Denis Berthod suggested, by adding abstract types by hand instead of having constants in the initial environment. You can also embed the natural numbers in Ocaml's type system by declaring the following two types: type 'a s type z

[Caml-list] Dependent types ?

2011-09-27 Thread Damien Guichard
That's pretty cool, everyone and his mother has a solution to the proposed problem. I think, for the sake of exhaustivity, i can share my own weird hack. It can express all power of 2 sizes (for example add, mul and div). It uses a nested data type. type 'a size = | Word of 'a | DWord

Re: Re: [Caml-list] Dependent types ?

2011-09-26 Thread Denis Berthod
Sorry, foo = add -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs

Re: [Caml-list] Dependent types ?

2011-09-26 Thread Yaron Minsky
As written, the behavior of the types might not be what you expect, since addition of two 16 bit ints may result in an int that requires 17 bits. When using phantom types, you need to be especially careful that the types mean what you think they mean. On Sep 26, 2011 8:13 AM, Denis Berthod

Re: [Caml-list] Dependent types ?

2011-09-26 Thread Jocelyn Sérot
Thanks to all for your answers. Phantom types could be a solution but we must declare a new type for each possible size, which is cumbersome / annoying. Moreover, since i'm writing a DSL, the fact that they do not require a modification to the existing type system is not really an

Re: [Caml-list] Dependent types ?

2011-09-26 Thread Gabriel Scherer
Phantom types could be a solution but we must declare a new type for each possible size, which is cumbersome / annoying. If you define the type system yourself, you can easily add a family of type constants `sizen` (with `n` an integer literal) to the default environment of the type checker.

Re: [Caml-list] Dependent types ?

2011-09-26 Thread oliver
On Mon, Sep 26, 2011 at 01:42:51PM +0200, Jocelyn Sérot wrote: Hello, I've recently come across a problem while writing a domain specific language for hardware synthesis (http://wwwlasmea.univ-bpclermont.fr/Personnel/Jocelyn.Serot/caph.html [...] Very interesting. I also once thought