Re: Algebraic data types in clojure.contrib

2009-03-02 Thread Konrad Hinsen
On 02.03.2009, at 01:50, Rich Hickey wrote: I was wondering if you considered using maps or struct-maps for this. One of my pet peeves with algebraic data types is the unnamed, positional nature of the components/fields. It always bothers me you have to rename the fields in every pattern

Re: Algebraic data types in clojure.contrib

2009-03-01 Thread Rich Hickey
On Feb 26, 4:06 pm, Konrad Hinsen konrad.hin...@laposte.net wrote: On 26.02.2009, at 10:00, Konrad Hinsen wrote: I know, but as I said, my current implementation is just a proof of concept. It is not viable for production use for a variety of reasons. I was planning to replace it by

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Konrad Hinsen
On 26.02.2009, at 08:47, Jeff Valk wrote: String representation obviously uses :type now in a very particular way. I'm not sure where this happens though. Can anyone shed some light on the details? print-method now dispatches on type, rather than class as it did before. There is no

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Konrad Hinsen
On 26.02.2009, at 01:51, Rich Hickey wrote: You raise interesting issues and I'd like to explore them further. I'm not sure the issues you have with type-tag-or-class dispatch are all that prohibitive. In any case, I've added a type function that returns the :type metadata or the class if

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Laurent PETIT
2009/2/26 Konrad Hinsen konrad.hin...@laposte.net On 26.02.2009, at 01:51, Rich Hickey wrote: You raise interesting issues and I'd like to explore them further. I'm not sure the issues you have with type-tag-or-class dispatch are all that prohibitive. In any case, I've added a type

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Konrad Hinsen
On Feb 26, 2009, at 1:51, Rich Hickey wrote: You raise interesting issues and I'd like to explore them further. I'm not sure the issues you have with type-tag-or-class dispatch are all that prohibitive. In any case, I've added a type function that returns the :type metadata or the class if

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Rich Hickey
On Feb 26, 4:00 am, Konrad Hinsen konrad.hin...@laposte.net wrote: On 26.02.2009, at 01:51, Rich Hickey wrote: You raise interesting issues and I'd like to explore them further. I'm not sure the issues you have with type-tag-or-class dispatch are all that prohibitive. In any case, I've

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Rich Hickey
On Feb 26, 4:17 am, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/2/26 Konrad Hinsen konrad.hin...@laposte.net On 26.02.2009, at 01:51, Rich Hickey wrote: You raise interesting issues and I'd like to explore them further. I'm not sure the issues you have with

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Rich Hickey
On Feb 26, 6:19 am, Konrad Hinsen konrad.hin...@laposte.net wrote: On Feb 26, 2009, at 1:51, Rich Hickey wrote: You raise interesting issues and I'd like to explore them further. I'm not sure the issues you have with type-tag-or-class dispatch are all that prohibitive. In any case, I've

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Laurent PETIT
2009/2/26 Rich Hickey richhic...@gmail.com On Feb 26, 4:17 am, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/2/26 Konrad Hinsen konrad.hin...@laposte.net On 26.02.2009, at 01:51, Rich Hickey wrote: You raise interesting issues and I'd like to explore them further.

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Laurent PETIT
Would it make sense to make instance?/type-instance?/type .. multimethods themselves ? 2009/2/26 Konrad Hinsen konrad.hin...@laposte.net On 26.02.2009, at 01:51, Rich Hickey wrote: You raise interesting issues and I'd like to explore them further. I'm not sure the issues you have with

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Rich Hickey
On Feb 26, 8:30 am, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/2/26 Rich Hickey richhic...@gmail.com On Feb 26, 4:17 am, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/2/26 Konrad Hinsen konrad.hin...@laposte.net On 26.02.2009, at 01:51, Rich Hickey wrote: You

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Laurent PETIT
2009/2/26 Rich Hickey richhic...@gmail.com On Feb 26, 8:30 am, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/2/26 Rich Hickey richhic...@gmail.com On Feb 26, 4:17 am, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/2/26 Konrad Hinsen konrad.hin...@laposte.net

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread mikel
On Feb 25, 6:51 pm, Rich Hickey richhic...@gmail.com wrote: user= (type #^{:type ::Fred} [1 2 3]) :user/Fred This is extremely appealing, as David said, for those of us building type systems for our application data. There's one wart for my particular use: (binding [*print-dup* true]

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Jeff Valk
Thanks for the insight, Konrad. I know this is a sideshow to the larger discussion on types, but it does present an unexpected usability issue. On 26 February 2009 at 02:44, Konrad Hinsen wrote: The fix is to provide a default implementation for print-method. Try executing this:

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Konrad Hinsen
On 26.02.2009, at 10:00, Konrad Hinsen wrote: I know, but as I said, my current implementation is just a proof of concept. It is not viable for production use for a variety of reasons. I was planning to replace it by something based on gen-class and proxy, but I will first try to get away

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread Jeffrey Straszheim
Is there any reason they cannot be implemented as structs with some sort of type tag? On Wed, Feb 25, 2009 at 10:26 AM, Konrad Hinsen konrad.hin...@laposte.netwrote: I have just added a new library to clojure.contrib. It provides a proof-of-concept implementation of algebraic data types. An

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread Konrad Hinsen
On Feb 25, 2009, at 16:32, Jeffrey Straszheim wrote: Is there any reason they cannot be implemented as structs with some sort of type tag? I suspect that could be done, but some nice features would be lost: 1) User-friendly printing. I implement the multimethods print-method and print-dup

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread David Nolen
1) User-friendly printing. I implement the multimethods print-method and print-dup for my classes, which allows me to specify how objects are printed. print- method and print-dup dispatch on class, so my types need to be classes or at least derive from a class that is distinct from the

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread Konrad Hinsen
On Feb 25, 2009, at 17:40, David Nolen wrote: Should print and println be multimethods? It seems the ability to custom print a data structure would be generally useful. It's already there, just not documented as far as I know. All the printing routines end up calling

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread Rich Hickey
On Feb 25, 12:19 pm, Konrad Hinsen konrad.hin...@laposte.net wrote: On Feb 25, 2009, at 17:40, David Nolen wrote: Should print and println be multimethods? It seems the ability to custom print a data structure would be generally useful. It's already there, just not documented as far as

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread David Nolen
This is nothing short of amazing for those who want to build ad-hoc type systems. (defstruct #^{:type ::my-struct} my-struct :a :b) (type #'my-struct) ; - :user/my-struct! I have a lot of code fixing to do now :) Also Konrad's point that using multimethods for dispatch-fns would be ugly, but

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread Chouser
On Wed, Feb 25, 2009 at 10:09 PM, David Nolen dnolen.li...@gmail.com wrote: This is nothing short of amazing for those who want to build ad-hoc type systems. Plus custom printing. (defmethod print-method ::Foo [o w] (doto w (.write #Foo: ) (.write (:x o)) (.write ))) (defn

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread Jeff Valk
How about appending type metadata automagically... (defstruct stuff :a :b) (defmacro make Creates a new instance of struct t and appends 'type' t as metadata [t vs] `(with-meta (struct ~t ~...@vs) {:type (keyword (str *ns*) (name '~t))})) user (make stuff 1 2) {:a 1, :b 2} user

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread Adrian Cuthbertson
Hmm, I get a stack overflow when trying that make macro. After using macroexpand-1... (with-meta (struct stuff 1 2) {:type (keyword (str *ns*) (name (quote stuff)))}) I still get the stack overflow. I'm on svn 1307, jdk 1.5 mac osx. Any ideas? Regards, Adrian. On Thu, Feb 26, 2009 at 7:08 AM,

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread Jeff Valk
On 25 February 2009, Adrian Cuthbertson wrote: Hmm, I get a stack overflow when trying that make macro. After using macroexpand-1... (with-meta (struct stuff 1 2) {:type (keyword (str *ns*) (name (quote stuff)))}) I still get the stack overflow. I'm on svn 1307, jdk 1.5 mac osx. Any