Monday, December 03, 2007

Will Closures in Java 7 help in making Functional Programming mainstream ?

Of late, there has been a lot of discussions on the usage of advanced programming idioms in the developers' community. Are we getting too much confined within the limits of strongly typed object-oriented paradigms and ignoring the power that dynamic non object oriented languages (read functional languages) have to offer ? Some of the blogs put forward the strawman's argument dismissing the usage of dynamic languages and more powerful abstractions as somewhat elitist and not suitable for the mass programmers. C# has added lots of functional paradigms to the language, Microsoft has positioned F# as a mainstream functional language for the .NET platform. Ruby has lots of functional features, Erlang has started being in the limelight and Haskell still reigns supreme amongst all favorites in reddit postings.

Still the adoption rate is not heartening enough and there are enough indications of apprehensions from the corners who make the masses. Is it the fear of dynamic typing or the lack of tools for refactoring support that's holding us back ? Or will the functional programming support from today's most widely used enterprise language can act as the catalyst towards easier adoption of folds and unfolds ?

I am not much of a believer in the strawman argument. But I think the push has to come from the medium which controls the balance and there is no denying the fact that today's enterprise programmers do Java for a living.

How close are we to getting closures in Java 7 ?

Do I get ..


public static <T,U> U fold(List<T> us,{T,U=>U} fun, U init) {
    U acc = init;
    for(T elem : us) {
        acc = fun.invoke(elem, acc);
    }
    return acc;
}



even though I would like to have ..


public static <T,U> U fold(List<T> us,{T,U=>U} fun, U init) {
    if (us.size() == 0) {
        return init;
    }
    return fold(us.subList(1, us.size()),
                fun, fun.invoke(us.get(0),
                init));
}



Either way I should be able to write ..


List<Integer> ints = new ArrayList<Integer>();
//.. populate ints
fold(ints,
      {Integer elem,Integer acc=>elem + acc},
    0);



With Neal Gafter's prototype, I can already write this, though we need TCO in order to play around with meaningful functional control structures.

16 comments:

Ricky Clarkson said...

Gah. Haskell is not dynamically typed at all. In fact, it has complete type erasure - no types exist at runtime.

Dynamic typing is not equivalent to functional programming whatsoever - in fact most of the innovation in functional programming comes from statically-typed languages like Haskell, Clean and Scala, these days.

Debasish said...

@Ricky: I did not tell that Haskell is dynamically typed. What I meant was that the fear for dynamic typing and lack of tools have also led to lesser adoption of functional paradigms in the programming world. Two of the most popular languages to support functional programming today - Ruby and Erlang are dynamically typed. Hence if we get static typing + functional paradigms from Java 7, then it can act as a catalyst for increased adoption of functional paradigms amongst today's enterprise programmers. A developer using Java today can more easily define a fold in Java 7, since he is familiar with the language and can relate that it is not that difficult to pick up a new technique of functional abstraction. Then tomorrow he will also try out Haskell since his initial fears towards functional programming have been allayed through Java.

Neal Gafter said...

I think there is a reasonable chance that jsr292 will provide support for TCO in JDK7.

Flying Frog Consultancy Ltd. said...

Perhaps surprisingly, OCaml is already as popular as Haskell and Erlang on the Linux OS, according to the Debian and Ubuntu package popularity contests. OCaml and Erlang are also the fastest growing functional programming languages.

Ricky Clarkson said...

Presumably OCaml is needed by some programs then, because you're the only user I've noticed.

Many people refer to it as something they used to do, though often fondly.

By what measure is OCaml the fastest growing functional language?

Are you returning to Scala soon? I enjoyed parts of your posts to the Scala mailing list.

Flying Frog Consultancy Ltd. said...

Hi Ricky,

The Debian and Ubuntu package popularity contests track the number of installs of each package among the subscribers to the contest.

Here are the current number of installed development environments for the most popular functional programming languages:

OCaml: 5757
Erlang: 5626
Haskell: 5601
Common Lisp: 4680
Scheme: 3651
Scala: 189

As you can see, OCaml is among the most popular, with many thousands of registered installs (and many more will not be registered). I already knew this, of course, because we have hundreds of paying customers using OCaml extensively in their work, ranging from chip design at Intel to shoe making in Italy.

I recently measured the increase in popularity over the past month:

OCaml: 551
Erlang: 548
Haskell: 498
Common Lisp: 360
Scheme: 334
Scala: 18

The error is quite big because these values fluctuate but you can see that all of the functional languages are basically growing at the same proportional rate of ~10% growth per month, i.e. there is no evidence for a current favorite language that is exploding in popularity.

Scala is not yet anything like as popular as OCaml. As a company we have discovered that we can turn a profit from product lines built around languages that are at least as popular as OCaml, which means we could potentially earn money from Haskell and Erlang (and F#) but not yet from Scala.

Although Scala is an interesting language, as a pioneer of functional programming on the JVM, I feel that its design has not learned sufficiently from the ML family of languages (e.g. as F# did). The most glaring omission is the lack of automatic generalization in Scala, which means you must define lots of types unnecessarily. This is one of the main sources of the brevity of the ML family of languages and it is sorely missed, essentially rendering Scala much less suitable for the kind of interactive technical computing that we specialize in.

I believe that we need a new functional programming language that draws upon the relative merits of Haskell, OCaml and F#. I am working towards the goal of creating this language using LLVM as a backend. My preliminary findings are amazing: LLVM makes it easy to achieve and even exceed the performance of OCaml's current implementation (which is famous for being the fastest functional programming language there is) in a variety of important test cases.

The main problem is that we do not yet have a GC and run-time, not even a working example. However, I believe it will be easy to obtain performance between that of Scala/F# and OCaml for GC-intensive code simply because the JVM and .NET are optimized for Java/C# which makes them ~5x slower for functional programming.

plush said...

companies marketing mineral makeups and also get the best bargains in mineral makeup you can imagine,
find aout how to consolidate your students loans or just how to lower your actual rates.,
looking for breast enlargements? in Rochester,
homeopathy for eczema learn about it.,
Allergies, information about lipitor,
save big with great bargains in mineral makeup,

change edition interviewing motivational people preparing second
,

interviewing motivational people preparing second time
,

interviewing people motivational preparing for a second time
,

black mold exposure
,

black mold exposure symptoms
,

black mold symptoms of exposure
,

free job interview questions
,

free job interview answers
,

interview answers to get a job
,

lookfor hair styles for fine thin hair
,

search hair styles for fine thin hair
,

hair styles for fine thin hair
,

beach resort in the philippines
,

great beach resort in the philippines
,

luxury beach resort in the philippines
,
iron garden gates, here,
iron garden gates,
wrought iron garden gates
, here
,
wrought iron garden gates
,
You: The Owner's Manual: An Insider's Guide to the Body That Will Make You Healthier and Younger
,
eat eating mindless more than think we we why
,


texturizer,
texturizers here,
black hair texturizer,
find aout how care curly hair,
find about how to care curly hair,
care curly hair,
lipitor rash,
lipitor reactions,
new house ventura california,
the house new houston tx,
new house washington dc,
new house pa philadelphia,
san antonio tx house new,
house new pa philadelphia,
new house washington dc,
new house ventura california,
the house new houston tx,
house new san antonio tx,
the house new houston tx, that you are looking for,
new house ventura california, you need to buy,
new house washington dc,
house new pa philadelphia,
new house san antonio tx,

hair surgery transplant
,

air filter allergy
,

refurbished dell laptop computers
,

hair surgery transplant
,

air filter allergy
,

refurbished dell laptop computers
,

hair surgery transplant
,

air filter allergy
,

refurbished dell laptop computers
,

chocolate esophagus heartburn study
,

chocolate esophagus heartburn study
be informed,

digestion healing healthy heartburn natural preventing way
,

digestion healing healthy heartburn natural preventing way
,
sew skirts, 16simple styles you can make!,
sew what skirts 16 simple styles you,
rebates and discounts on sunsetter awnings,
sunsetter awnings discounts and rebates,
discount on sunsetter awnings


truck and bus tires 12r 22.5, get the best price,
tires truck and bus 12r 22.5 best price,
tires truck bus tires12r 22.5 best price,
plush car seat strap covers,
car seat strap covers,plush,
car seat strap, plush covers,
oscoda voip phone systems, the best!,
oscoda voip the phone system,
oscoda voip phone systems,
exterior iron gates,
oriental wrought iron gates,
powder coated iron garden fencing,

photo soft said...

black mold exposure,
black mold symptoms of exposure,

wrought iron garden gates,
your next iron garden gates, here,

hair styles for fine thin hair,
search hair styles for fine thin hair,

night vision binoculars,
buy, night vision binoculars,

lipitor reactions,
lipitor reactions,

luxury beach resort in the philippines,
beach resort in the philippines,

homeopathy for baby eczema.,
homeopathy for baby eczema.,

save big with great mineral makeup bargains,
companies marketing mineral makeups,

prodam iphone praha,
Apple prodam iphone praha,

iphone clone cect manual,
manual for iphone clone cect,

fero 52 binoculars night vision,
fero 52 night vision,

best night vision binoculars,
buy, best night vision binoculars,

computer programs to make photo albums,
computer programs, make photo albums,

said...

群馬 ハウスメーカー
埼玉 ハウスメーカー
盲導犬
治験
出産祝い
クレジットカード決済
24そんぽ24
自動車保険
自動車保険 比較
アメリカンホームダイレクト
不動産
出会い
出会い系
出会い系サイト
出会いサイト
チューリッヒ
自動車 保険 見積
ソニー損保
カード決済

said...

アクサダイレクト
インプラント
ショッピングカート
東京 ホームページ制作
不動産投資
知多半島 温泉
知多半島 旅館
埼玉 不動産
三井ダイレクト
カラーコンタクト
カーボンオフセット
コンタクトレンズ
クレジットカード 海外旅行保険
ゼネラリ
広島 不動産
お見合いパーティー
募金
松山市 不動産

said...

プリンセスルーム
婚約指輪
障害者
結婚相談所 東京
国際協力
結婚指輪
浮気調査
アスクル

said...

国際協力ユーザーの皆さまが大手ECサイトで商品をご購入される際、グリーンクリックを経由していただくだけでECサイトから支国際協力。グリーンクリックを利用することで、商品の購入価 格が変わったり、寄

said...

自律神経失調症・障害者をたった3ヶ月で克服したマル秘テクニックを紹介します!障害者ネイティブによるスピーディな授業はまさに圧巻の

said...

盲導犬ユーザーの皆さまが大手ECサイトで商品をご購入される際、グリーンクリックを経由していただくだけでECサイトから支盲導犬。グリーンクリックを利用することで、商品の購入価 格が変わったり、

said...

出会いサイト★業界no.1★圧倒的登録数で催促近距離アポが可能出会いサイト!素人獲得数も、広告部数も業界最多!"

Anonymous said...

情趣用品,情趣用品,情趣用品,情趣用品,情趣,情趣,情趣,情趣,按摩棒,震動按摩棒,微調按摩棒,情趣按摩棒,逼真按摩棒,G點,跳蛋,跳蛋,跳蛋,性感內衣,飛機杯,充氣娃娃,情趣娃娃,角色扮演,性感睡衣,SM,潤滑液,威而柔,香水,精油,芳香精油,自慰套,自慰,性感吊帶襪,吊帶襪,情趣用品加盟AIO交友愛情館,情人歡愉用品,美女視訊,情色交友,視訊交友,辣妹視訊,美女交友,嘟嘟成人網,成人網站,A片,A片下載,免費A片,免費A片下載愛情公寓,情色,舊情人,情色貼圖,情色文學,情色交友,色情聊天室,色情小說,一葉情貼圖片區,情色小說,色情,色情遊戲,情色視訊,情色電影,aio交友愛情館,色情a片,一夜情,辣妹視訊,視訊聊天室,免費視訊聊天,免費視訊,視訊,視訊美女,美女視訊,視訊交友,視訊聊天,免費視訊聊天室,情人視訊網,影音視訊聊天室,視訊交友90739,成人影片,成人交友,美女交友,微風成人,嘟嘟成人網,成人貼圖,成人電影,A片,豆豆聊天室,聊天室,UT聊天室,尋夢園聊天室,男同志聊天室,UT男同志聊天室,聊天室尋夢園,080聊天室,080苗栗人聊天室,6K聊天室,女同志聊天室,小高聊天室,上班族聊天室,080中部人聊天室,同志聊天室,聊天室交友,中部人聊天室,成人聊天室,一夜情聊天室,情色聊天室,寄情築園小遊戲情境坊歡愉用品,情境坊歡愉用品,情趣用品,成人網站,情人節禮物,情人節,AIO交友愛情館,情色,情色貼圖,情色文學,情色交友,色情聊天室,色情小說,七夕情人節,色情,情色電影,色情網站,辣妹視訊,視訊聊天室,情色視訊,免費視訊聊天,美女視訊,視訊美女,美女交友,美女,情色交友,成人交友,自拍,本土自拍,情人視訊網,視訊交友90739,生日禮物,情色論壇,正妹牆,免費A片下載,AV女優,成人影片,色情A片,成人論壇,情趣,免費成人影片,成人電影,成人影城,愛情公寓,成人影片,保險套,舊情人,微風成人,成人,成人遊戲,成人光碟,色情遊戲,跳蛋,按摩棒,一夜情,男同志聊天室,肛交,口交,性交,援交,免費視訊交友,視訊交友,一葉情貼圖片區,性愛,視訊,視訊聊天,A片,A片下載,免費A片,嘟嘟成人網,寄情築園小遊戲,女同志聊天室,免費視訊聊天室,一夜情聊天室,聊天室