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 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 something based on ge

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-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: > > (def

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread mikel
On Feb 25, 6:51 pm, Rich Hickey 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] (prn-str #^{:

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Laurent PETIT
2009/2/26 Rich Hickey > > > > On Feb 26, 8:30 am, Laurent PETIT wrote: > > 2009/2/26 Rich Hickey > > > > > > > > > > > > > On Feb 26, 4:17 am, Laurent PETIT wrote: > > > > 2009/2/26 Konrad Hinsen > > > > > > > On 26.02.2009, at 01:51, Rich Hickey wrote: > > > > > > > > You raise interesting i

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Rich Hickey
On Feb 26, 8:30 am, Laurent PETIT wrote: > 2009/2/26 Rich Hickey > > > > > > > On Feb 26, 4:17 am, Laurent PETIT wrote: > > > 2009/2/26 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 >

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 > > 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 disp

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Laurent PETIT
2009/2/26 Rich Hickey > > > > On Feb 26, 4:17 am, Laurent PETIT wrote: > > 2009/2/26 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

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Rich Hickey
On Feb 26, 6:19 am, Konrad Hinsen 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 added a type func

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Rich Hickey
On Feb 26, 4:17 am, Laurent PETIT wrote: > 2009/2/26 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 proh

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Rich Hickey
On Feb 26, 4:00 am, Konrad Hinsen 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 added a type funct

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 i

Re: Algebraic data types in clojure.contrib

2009-02-26 Thread Laurent PETIT
2009/2/26 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

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 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 d

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

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, J

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} us

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread Chouser
On Wed, Feb 25, 2009 at 10:09 PM, David Nolen 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 "#"))) (defn make-foo [x] #^{:type ::Foo} {:x x}) user=> (make-foo "whee

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 act

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread Rich Hickey
On Feb 25, 12:19 pm, Konrad Hinsen 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 I know. All the >

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread mikel
On Feb 25, 9:26 am, Konrad Hinsen wrote: > I have just added a new library to clojure.contrib. It provides a   > proof-of-concept implementation of algebraic data types. An example   > for what you can do with it: > > (deftype tree >    empty-tree >    (leaf value) >    (node left-tree right-tr

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 clojure.core/print-m

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 th

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-du

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 wrote: > > I have just added a new library to clojure.contrib. It provides a > proof-of-concept implementation of algebraic data types. An example > for what you c