That made me wonder, is there a similar unified query capability on the road map for Fan? (expression trees, anonymous objects etc...)
Because I think that would be the single biggest feature in convincing coworkers its time to move on from Java.
jodastephenWed 7 Oct 2009
What power do you see it adding? What are your use cases that it helps solve?
brianWed 7 Oct 2009
Here are my thoughts on list comprehensions and LINQ. Manipulating lists of objects are perhaps one of the most common things done in software. There are lots of things we do with lists, but from a functional perspective we do a couple of things all the time:
map: translate each item from the list into another object
filter: create a new list based upon some selection criteria
fold/reduce: aggregate a list of things into a single object
sort: order the list according some comparison function
These functions are already available in Fan today, and indeed in any language which has closures. But they are so common, that some languages such as Python have taken the next step and provided first class syntax for list manipulation.
List comprehensions are a very nice way to map/filter one or more lists. For a single list this is just sugar for map/findAll. For multiple lists, it can be really nice compared to trying to use APIs.
LINQ builds upon list comprehensions with some really powerful ideas. First LINQ embraces more of the list functions like fold, sort, etc than list comprehensions. But what LINQ really brings to the table is the ability to map a LINQ expression to an AST at runtime. This means I can take an expression which manipulates lists and do arbitrary things with it such as translate it into SQL or optimize a filter based on indices.
Another thing that I find fascinating is the latest work Microsoft has done with LINQ-to-Events (Reactive framework) which is based upon the principle that push eventing is the mathematical dual of poll iterators. This allows us to treat collections as an event stream and then apply the same normalized list manipulation expressions for filtering, mapping, and folding. If you haven't watched Erik Meijer presentations on this, I highly recommend it.
I do not particularly like C#'s SQL like LINQ syntax. However, I really want to embed key ideas into Fan:
first class syntax for list manipulation
treating collections and events consistently as streams
ability to evaluate an expression as AST at runtime
I am exploring many of the ideas today in Bespin with my commercial SkyFoundry work. I expect that experience will generate a lot of ideas which might be rolled back into Fan.
I ran into the Reactive Framework concept recently, collected a few links and been thinking about how it related to our earlier discussions here.
I'm not yet convinced that LINQ is such a great deal; I kind of get the feeling that Redmond has a new toy. The idea behind the Reactive Framework concept, treating Observables and Iterables as duals of each other, seems really interesting, and leads to some neat things (see Flapjax links below). The attempts I've seen to express event handling as LINQ queries seem a lot more awkward.
Maybe I just need to be educated some more.
It seems to me like the Functional Programming people (Flapjax compiler is written in Haskell) have a handle on something here; I'm not sure though how best it should fit with Fan.
I'm enjoyed Rx video as well, but it would be also interesting to recall this thread: Mutable Message Passing. Fundamental question is Clojure-alike model (immutable values, STM, etc) would be good for Fan?
At least introducing Clojure refs into Fan language, we'll not only get all the Clojure benefits like immutable values (I mean everything immutable including collections) and controlled manipulation of state (STM) but in connection with Rx it looks like Ref<T> (Clojure) can be used as IObservalbe<T> (Rx). So we'd be able to Attach to any ref and build Rx-alike framework for general purpose reactive programming.
Just imagine:
const class Button //sorry const is obsolete - everything is immutable
{
ref Str caption //Clojure alike-ref: read and write
//controlled within transaction scope, refers to the immutable string
Geometry geometry //just normal Fan immutable geometry field
}
Button b
b.caption.attach { ... }
And this reactive events will be controlled with same transaction mechanism :)
Kind Regards, Andrey
casperbangWed 7 Oct 2009
What power do you see it adding? What are your use cases that it helps solve?
Oh gee, where to start? For one thing, I am sick and tired of thousands of lines of type-unsafe, uncomposable JPQL buried inside Java annotations. To many of us, the work day consists of an awful lot of data projection.
First LINQ embraces more of the list functions like fold, sort, etc than list comprehensions.
And what about joins? The fact that you can join across... anything, say between an XML file, the Windows registry, file system, an LDAP directory etc.
casperbang Wed 7 Oct 2009
I saw LINQ mentioned in another thread.
That made me wonder, is there a similar unified query capability on the road map for Fan? (expression trees, anonymous objects etc...)
Because I think that would be the single biggest feature in convincing coworkers its time to move on from Java.
jodastephen Wed 7 Oct 2009
What power do you see it adding? What are your use cases that it helps solve?
brian Wed 7 Oct 2009
Here are my thoughts on list comprehensions and LINQ. Manipulating lists of objects are perhaps one of the most common things done in software. There are lots of things we do with lists, but from a functional perspective we do a couple of things all the time:
These functions are already available in Fan today, and indeed in any language which has closures. But they are so common, that some languages such as Python have taken the next step and provided first class syntax for list manipulation.
List comprehensions are a very nice way to map/filter one or more lists. For a single list this is just sugar for map/findAll. For multiple lists, it can be really nice compared to trying to use APIs.
LINQ builds upon list comprehensions with some really powerful ideas. First LINQ embraces more of the list functions like fold, sort, etc than list comprehensions. But what LINQ really brings to the table is the ability to map a LINQ expression to an AST at runtime. This means I can take an expression which manipulates lists and do arbitrary things with it such as translate it into SQL or optimize a filter based on indices.
Another thing that I find fascinating is the latest work Microsoft has done with LINQ-to-Events (Reactive framework) which is based upon the principle that push eventing is the mathematical dual of poll iterators. This allows us to treat collections as an event stream and then apply the same normalized list manipulation expressions for filtering, mapping, and folding. If you haven't watched Erik Meijer presentations on this, I highly recommend it.
I do not particularly like C#'s SQL like LINQ syntax. However, I really want to embed key ideas into Fan:
I am exploring many of the ideas today in Bespin with my commercial SkyFoundry work. I expect that experience will generate a lot of ideas which might be rolled back into Fan.
KevinKelley Wed 7 Oct 2009
Relating back to the Facets, Symbols and Bound Slots thread...
I ran into the Reactive Framework concept recently, collected a few links and been thinking about how it related to our earlier discussions here.
I'm not yet convinced that LINQ is such a great deal; I kind of get the feeling that Redmond has a new toy. The idea behind the Reactive Framework concept, treating Observables and Iterables as duals of each other, seems really interesting, and leads to some neat things (see Flapjax links below). The attempts I've seen to express event handling as LINQ queries seem a lot more awkward.
Maybe I just need to be educated some more.
It seems to me like the Functional Programming people (Flapjax compiler is written in Haskell) have a handle on something here; I'm not sure though how best it should fit with Fan.
Some links:
Erik Meijer Reactive Framework talk, slideshow:
http://download.microsoft.com/download/7/6/A/76A69AE5-72B5-4005-BBD9-7EA5F4795014/23-ErikMeijer-LiveLabsReactiveFramework.wmv
Jafar Husain blog on Rx (LINQ to Events):
http://themechanicalbride.blogspot.com/2009/07/introducing-rx-linq-to-events.html
Functional Reactive Programming:
FlapJax (Reactive Javascript):
http://www.flapjax-lang.org/
Lifting in FlapJax:
http://www.weaselhat.com/2007/08/11/lifting-in-flapjax/
andrey Wed 7 Oct 2009
Hi folks,
I'm enjoyed Rx video as well, but it would be also interesting to recall this thread: Mutable Message Passing. Fundamental question is Clojure-alike model (immutable values, STM, etc) would be good for Fan?
At least introducing Clojure refs into Fan language, we'll not only get all the Clojure benefits like immutable values (I mean everything immutable including collections) and controlled manipulation of state (STM) but in connection with Rx it looks like Ref<T> (Clojure) can be used as IObservalbe<T> (Rx). So we'd be able to Attach to any ref and build Rx-alike framework for general purpose reactive programming.
Just imagine:
And this reactive events will be controlled with same transaction mechanism :)
Kind Regards, Andrey
casperbang Wed 7 Oct 2009
Oh gee, where to start? For one thing, I am sick and tired of thousands of lines of type-unsafe, uncomposable JPQL buried inside Java annotations. To many of us, the work day consists of an awful lot of data projection.
And what about joins? The fact that you can join across... anything, say between an XML file, the Windows registry, file system, an LDAP directory etc.