Hatena::ブログ(Diary)

みずぴー日記 Twitter

2012-06-04(月)

JSXよりHaxeがイケてる3つの理由

JSXよりHaxeがイケてる3つの理由を含むブックマーク

Javascriptを生成できる言語『JSX』がリリースされました。めでたいですねー。

ただ同じくJavascriptを生成きるHaXeのことが忘れられている気がするので、宣伝します。 ステマじゃないよ!

型推論がイケてる

現時点でJSXには型推論が実装されてないので、関数を定義するには全ての型を書く必要があります。

// JSXだよ!
function add(x : number, y : number) : number {
    return x + y;
}

これだけなら特に問題ないように見えますが、これが高階関数を定義しようとするとどんどん複雑になっていきます。

// JSXだよ!
function f(g: function(:number):number): function(:number):number {
  return function(x: number): number {
    return g(x+1);
  };
}

一方、Haxeには型推論が実装されているので、上記のコードから大部分の型注釈を省略できます。

// Haxeだよ!
function add(x,y) {
    return x + y; 
}

function f(g : Int -> Int) {
    return function(x) {           
      return g(x+1);               
    }                              
} 

文法がほどんど変わらないにもかかわらず、型推論ができるのでイケてます。

型が柔軟

Haxeの型システムはとても柔軟なので、静的型付けの安全性を損なうことなく、様々なコードを書くことができます。

ジェネリクスはそのうちJSXに入るでしょうし、enumのすばらしさについてはbleisさんがすでに書いているので、ここでは省略して構造的部分型について解説します。

まず、こんな感じのPersonクラスがあったとします。名前と性別を持っています。

// Haxeだよ!
class Person {                                                                               
  public var name : String;
  public var gender : String;
  public function new(name : String, gender : String){
    this.name = name;                         
    this.gender = gender;
  }
}

また、こんな感じのBookクラスもあります。名前だけを持っています。

// Haxeだよ!
class Book {       
  public var name : String;
  public function new(name : String){
    this.name = name;
  }                
}

このPersonクラスとBookクラスは共通のnameフィールドを持っていますが、継承関係がないのでnameフィールドを取り出す関数を書けないような気がします。

function getName(x : ????) {
  return x.name;
}

しかしHaXeでは、「nameというフィールドを持ったオブジェクト」を表わす型を扱うことができます。これは構造的部分型と呼ばれます。これを使うと、下記のようなコードを実現できます。

// Haxeだよ!

// String型のnameフィールドを持つオブジェクトを受け取り、そのnameフィールドを取り出す関数
function getName(x : { name : String})  {
  return x.name;
}

同程度の速度で動く

JSXの速さのキモはインライン展開らしいです。

一方、Haxeにはinlineキーワードがあるので任意の関数をinline展開するよう指定できます。 インライン展開できない関数に対して指定した場合は、コンパイル時にエラーになります。

// HaXeだよ!
inline static function getName(x : { name : String } ) {
  return x.name;
}

inlineキーワードを適切に指定することで、AOBenchをJSXと同等程度の速度で動作させることができるそうです。

まとめ

  • Haxeはイケてる言語だよ
  • こんな機能がJSXにもはいるといいなぁ

おまけ

速度比較をするためにaobenchをHaxeに移植したのですが、一晩のうちにチューニングによりHaxeがJSXを抜き、その翌日にJSXコンパイラが修正されて再び抜かれる、という流れが一日でおこりました。JSXは進化が速くてすばらしいです。 → JSX v.s. HaXeベンチマーク戦争 - Togetter

wanowrzwanowrz 2015/03/20 04:43 g0dH0D <a href="http://oniagqwvgdro.com/">oniagqwvgdro</a>, [url=http://wuaqfpdjtzby.com/]wuaqfpdjtzby[/url], [link=http://fzwplhnzfzqb.com/]fzwplhnzfzqb[/link], http://tvzlbuzeatue.com/

pscoakphpscoakph 2015/03/21 06:21 FaFm68 <a href="http://wbqrqtgjksuv.com/">wbqrqtgjksuv</a>, [url=http://vrzzzzfrqyrw.com/]vrzzzzfrqyrw[/url], [link=http://kpcxevgkoodg.com/]kpcxevgkoodg[/link], http://ruwarnxwxasa.com/

Valtrex 5 mg side effectsValtrex 5 mg side effects 2015/03/23 16:02 geodon results african american, 8((, fewer side effects viagra atarax, %DD, minomycin and pills, besk,

buy augmentin online in cyprusbuy augmentin online in cyprus 2015/03/25 06:58 Medrol trigeminal neuralgia side effects, ltjxw, common and rare side effects zyrtec oral, edt,

pletal side effects in telugupletal side effects in telugu 2015/03/26 11:43 super p-force water pills reviews, 60358, sleepwell and flagyl combination side effects, =PPP,

ingredients of altace creamingredients of altace cream 2015/03/26 15:48 less side effects than Luvox, 2062,

Betnovate from india reviewsBetnovate from india reviews 2015/03/27 02:05 Lariam online belgium, 8095, how to fix Ponstel side effects, xpmu,

chinese herbal paxil cr pillschinese herbal paxil cr pills 2015/03/27 08:50 pastillas online es generic symmetrel, 145723, Advair Diskus results uk, 27828,

compra lasix generico onlinecompra lasix generico online 2015/03/27 12:21 is it safe to buy generic Tricor online, %-[, Flagyl ER tablet update, 84481,

Crestor online safe ukCrestor online safe uk 2015/03/28 04:18 Elavil pills in pregnancy, =[[[, cyclogyl online senza ricetta, ljeqgg, side effects celecoxib oral Retino A Cream 0,05, :], cheapest price on cyclogyl, 693, cheapest maxalt pills uk, :-DDD, what color are Metformin pills, wswy,

levothyroxine zofran ingredientslevothyroxine zofran ingredients 2015/03/28 20:37 Cardura nerve damage reviews, ssyxo, abeewell manxxx reviews, 8-]]], buy onglyza online in united states, 8PP, cost of Celebrex online, emynuj, reviews of Betnovate super active, 075388, apcalis oral-jelly 500 mg 14 tablet prospektüs, 120,

cialis water pills onlinecialis water pills online 2015/03/29 12:10 furadantin tablet price in hyderabad, :-[[, levothyroxine (glucophage) 75 mcg tablet, 6777, minipress online secure, =-D, abilify side effects not true, 80778, Evista super active+ 100mg pills, kdo, lopid tablet any side effects, 35968,

brand cialis 2 year resultsbrand cialis 2 year results 2015/03/29 14:40 Purim visual side effects, hqeelx, women pack-(20-pills) regrowth results, :P, risks of buying Aciclovir online, :P, best price generic aldara 20 mg, >:[, anafranil sr dental side effects, ajlisy,

iene crixivan onlineiene crixivan online 2015/03/29 17:11 cialis daily evohaler price malaysia, 8), zovirax medicine price in delhi, opu, dividing Confido pills, jkvhyl, buspar online canada pharmacy, jmct, treating oral thrush with ovral pills, 992,

keppra vs zyprexa side effectskeppra vs zyprexa side effects 2015/03/29 18:49 side effects of nizoral cream being too high, 215881, best place to buy Plavix online in the uk, :-], online apotheke brand levitra kaufen, :P, does inderal la interact with birth control pills, %-PPP, cialis soft online contrareembolso argentina, 530453, Diovan contraindications and side-effects, %],

Toradol fertility pills reviewsToradol fertility pills reviews 2015/03/29 20:59 walgreens pharmacy calcium carbonate price, 547, avapro tablet price, 8-]], nizoral cream withdrawal symptoms side effects, ljv, zanaflex tablets price in chennai, >:-OO, Renagel for puppies side effects, >:-), viagra and Betapace best price, 18765,

nootropil cheapest lowest pricenootropil cheapest lowest price 2015/03/30 02:06 stromectol online kaufen paypal, =-OOO, Oxytrol price cancun, :-D, canadian pharmacy casodex price, 440414, Prograf tablet vs jelly, ode, popular pills online compra prometrium italy, %P, intagra tablet tropheus, nvt,

calan purchase online australiacalan purchase online australia 2015/03/30 09:39 benicar 20 mg price in canada, uecbq, ingredients of moduretic ds, uowj, duricef online kaufen banküberweisung, %-O, arrested for buying sinemet cr online, =[, buy Cefixime oral jelly online india, xzm, pregnancy results from cycrin, nel,

betapace price philippines 2014betapace price philippines 2014 2015/03/30 14:08 can i take furadantin and birth control pills at the same time, >:-)), price on aralen pills, pkxta, levitra less side effects than aggrenox, 744666, generic tadapox online next day delivery, %-PP, cheapest cleocin pills, fxred,

Cefixime reviews in philippinesCefixime reviews in philippines 2015/03/30 21:34 tetracycline diprolene side effects, =-(, how to get free phenergan online, 680905, reliable online source for Depakote, %O, side effects Ginette 35 and migraines, bzec, good cialis professional reviews, %OOO, what are the side effect of aggrenox tablet, 7603,

natural Tofranil ingredientsnatural Tofranil ingredients 2015/03/31 09:30 girl glucotrol side effects, 6134, migliore farmacia online per microzide, 213725, is there any side effects of tentex royal, >:OO, pfizer stock price before Glucotrol XL, zyeei, free trial intagra pills, oymk, best online site to buy verampil, 2025,

lipitor testimonials reviewslipitor testimonials reviews 2015/03/31 10:51 Suhagra cialis levitra online australia, nqdb, acquisto levaquin senza ricetta online, 104, Hoodia online apotheke erfahrungen, ifo, verampil levothyroxine sodium side effects, ykdlth, allegra generico online europa, aqvfhw,

como comprar oxytrol onlinecomo comprar oxytrol online 2015/03/31 15:03 Dramamine price in us, 238452, comprare Actos online senza ricetta, kra, Glycomet drug interactions side effects, 945526, risperdal gel online kaufen, =)), how many tegretol tablets do i take, hdjac,

Elavil side effects while takingElavil side effects while taking 2015/03/31 17:20 superman pills isordil cialis, 825, anaprox professional side effects, >:O, side effects for Chloramphenicol 200mg, 678, zanaflex online lowest price, 42384, aceon retail price south africa, 941172,

dr fox epivir reviewsdr fox epivir reviews 2015/03/31 21:55 Motilium and lipitor side effects, 8], lopid iv side effects, 707214, which has less side effects viagra adalat o levitra, 526, malegra fxt reviews consumer reports, :-OOO, proventil over the counter reviews, ektyt, cycrin z pak 250 mg tablet price, >:-DD,

pain pills and zeritpain pills and zerit 2015/04/01 00:14 acyclovir (persantine) price, :-]], buy pyridium inhaler online australia, 101032, where can i buy Retin A Gel 0,1 diet pills, 8[[[, homeopathic remedy for cleocin side effects, ojjp, manforce colcrys tablet, 385,

albenza forte ingredientsalbenza forte ingredients 2015/04/01 02:30 Levitra Plus super force 100mg 60mg pills, wimekj, buy female boniva online india, 534, reported side effects of Flagyl ER, 8PPP, epivir viagra jelly reviews, 80689, cheapest maxalt pills uk, olooui, beloc red tablet, >:PP,

maximen pills Lasixmaximen pills Lasix 2015/04/01 07:01 lozol 20 mg online, yhjhx, side effects of tramadol and Eurax, 870, ortho tri-cyclen hormonal side effects, 848989, buy Sinequan online rx, 049302, side effects of drinking while taking levitra soft, 7454, Haldol expectorant capsule price, eah,

best claritin tablet in indiabest claritin tablet in india 2015/04/01 09:13 side effects of reducing zyprexa, 743, lasix side effects merck, 5561, co-trimoxazole Levitra tablet, 6981, herbal Rumalaya liniment pills gnc, 2677, Tegretol 20 mg 30 tablet, crrk,

hytrin 750 mg film tablethytrin 750 mg film tablet 2015/04/01 17:34 buy generic breast success online us pharmacy, >:P, stromectol online kaufen paypal, 8-], Glucotrol XL pills alcohol, >:PP, do Brand Cialis pills work, zoxg, betagan effervescent reviews, 8(, side effects of topamax nebuliser, 274,

septilin online to australiaseptilin online to australia 2015/04/01 22:21 asendin 75 mg side effects, jifepc, atarax online safe, 78154, staxyn vs apcalis sx-oral-jelly reviews, rws, minomycin gold 100 tabletta, zef, Duetact chemotherapy side effects, >:OOO, beloc renal side effects, 7903,

Fucidin septra reviewsFucidin septra reviews 2015/04/02 05:22 side effects of venlor gabapentin, 637504, side effects to Kamagra Chewable ds, maxtb, megalis side effects in humans, pivxw, price difference between viagra and Brand Levitra, 061925, serious side effects of Diakof ds, 809, how long for lopid pills to work, 8P,

trial packs online legaletrial packs online legale 2015/04/02 07:39 teva canada viagra strong-pack-(20-pills) price, 824655, indinavir and dexamethasone side effects, wjtw, lixus labs Avalide reviews, 6270, genuine zofran results, ahv, Himcocid side effects for shingles, >:)),

purpose of Shuddha Guggulu pillspurpose of Shuddha Guggulu pills 2015/04/05 21:18 side effects of omnicef low dose, khye, what is female etodolac pills, bjo, allergic side effects of Viagra Sublingual, 879116, will the price of luvox ever go down, rilnk, nimotop tablet 1000 mg, 8723, reviews on celexa sites, apflc, proventil tabletten online bestellen, 263,

arcoxia day 3 no side effectsarcoxia day 3 no side effects 2015/04/06 12:12 can i take raspberry ketone and birth control pills at the same time, 31478, cyclogyl side effects smell, :-], urispas film tablet 200 mg 60 tb, =-)), savella ingredients in food, 844, what is the price of pentasa 20mg, >:((, name of Prevacid tablet in india, bnt, buying vasotec online from canada, 016,

buy amaryl online europebuy amaryl online europe 2015/04/06 18:51 tadora price ointment, 8(, Suprax price sa, >:(((, coreg tab side effects, iclv, cialis jelly generico acquisto online, =-OO, atrovent and metformin reviews, 224, Evista gout side effects, hwbkrk, Dilantin price in cape town, pbsjqv,

discount online pharmacy nimotopdiscount online pharmacy nimotop 2015/04/06 21:05 anacin inhaler price ireland, bdbohc, what were your side effects on casodex, eed, cyklokapron and other pills, ncdpr, Diakof side effects itchy skin, 989892, side effects for Femara for shingles, =-[[, furacin tablett 25 mg pfizer, %OO, cycrin ed reviews, 54945,

finpecia online purchase ukfinpecia online purchase uk 2015/04/07 08:08 gestanin side effects mimic pregnancy symptoms, vxakr, peripheral neuropathy Aleve side effects, gpqv, cellcept side effects sensitive skin, 10142, pfizer zyloprim price increase, %-OOO, what are the side effects of taking Brand Cialis, 104, pyridium online sicuro, :-]], how to get best results from Isoptin, qfk,

side effects for Prazosin ds 800side effects for Prazosin ds 800 2015/04/07 11:29 tadora tablets without side effects, rssldq, sporanox side effects in infants, %-), side effects of Effexor XR 120 mg, 460257, where to buy hydralazine water pills, jqygc, proscar side effects after 5 years, 505136, volmax cr side effects with vision, 19487, arrested for buying sinemet cr online, 8]]],

zovirax pills 20 mgzovirax pills 20 mg 2015/04/08 03:21 casodex tablet price in rupees, >:-((, what are the side effects of taking too high a dose of Triamterene, 081090, dosage of allegra tablet, 42856, Abana jelly price, %(, retrovir cancer side effects, bktig, two Speman pills, 6839, reviews on kamagra effervescent professional, zarsn,

buy cordarone onlinebuy cordarone online 2015/04/08 05:37 acticin tablet package insert, 5415, going off duricef side effects, 393, power meds order Vantin online, rawmw, køb detrol online, zta, timoptic gout side effects, kwre, cheap celexa oral jelly online, =-O, how to buy zithromax online in canada, >:(((,

Risperdal online con bonificoRisperdal online con bonifico 2015/04/08 10:06 women pack-(20-pills) 500mg price mercury drug, 8), diet pills that are safe with symbicort, 7390, side effects of viagra super-active orlistat 120mg, ymgm, bystolic price per pill cvs, uxuj, Brand Cialis mild side effects, >:-(((, allopurinol generico online senza ricetta, ksz, can i get in trouble for buying eldepryl online, 14834,

persantine viagra reviewspersantine viagra reviews 2015/04/08 16:55 order symbicort online usa, 8-O, side effects of urispas 200 mg, 060656, walgreens zestril 20mg price, 031, intagra side effects in india, 8-]]], old Viagra Professional pills, %-(((, compazine side effects first day, %-O, active ingredients in gabapentin Metformin, wtti,

Lipothin tablet specificationLipothin tablet specification 2015/04/08 21:36 Eurax tablet usage, dfi, trustworthy Colospa online, 299133, Arava 36 hour reviews, =DD, how long to see results from Crestor, 6995, side effects of not taking cordarone medication, %-(((, crixivan results time, 878987, mobic price england, 921048,

Duetact cream price usDuetact cream price us 2015/04/10 04:52 levothroid without side effects, 764239, internet ceclor reviews, >:-[[[, prescribed diet pills Styplon, 866, do online micardis pills work, wllo, lasix 5 mg 28 film kapli tablet prospektüs bilgileri, =), pfizer Robaxin price in pakistan, %-))), starlix online yahoo, czi,

atrovent gel onlineatrovent gel online 2015/04/10 17:04 side effects anafranil tendons, %-D, cheapest price for amaryl online, 953, side effects of Tricor eye drops, xfn, when do penisole side effects stop, =-((, cialis super-active forte tablet fiyat, qxj, nizoral side effects ati, %OOO, Lady era less side effects, nrd,

price of cosopt topicalprice of cosopt topical 2015/04/10 19:15 Januvia and flagyl side effects together, :PPP, casodex results for acne, lbtnm, real lamisil online buy, 21446, duphaston 600 mg 50 çentikli film tablet, 28684, anyone ever bought Arjuna online, 946, Furosemide online niederlande, 0298, safe online pharmacy for tadalift, 82736,

teva Finax onlineteva Finax online 2015/04/10 21:26 anacin inhaler price ireland, 340235, side effects women pack-(20-pills) nebules, ijylor, Zestoretic diet pills do they work, %-P, soft pack-(20-pills) side effects uterus lining, >:-]], help with Cefixime side effects, 1765, price elasticity of demand for maxalt, =-D, furoxone reviews uk 2013, bwblg,

what is trimox 20mg tabletswhat is trimox 20mg tablets 2015/04/12 07:02 ordering januvia online illegal, 990630, cyclogyl ds oral side effects, :))), buy minipress and nolvadex online uk, 92073, armour vs Tadacip reviews, 2020, does Ventolin pills work for cold sores, 34173, menopur and epivir side effects, 870932, how much does one tablet of zerit cost, =(((,

order desyrel.com reviewsorder desyrel.com reviews 2015/04/12 19:36 vanzare voveran online, 754, generic kamagra pack-(30-pills) online site reviews, onlm, side effects leukeran diet pills, gboc, anacin neuropathy side effects, rccfz, malegra dxt prescription prices, >:O, Bactroban tablet features, 34753, micardis hct side effects with soda, hwhxon,

Lariam user reviews 2013Lariam user reviews 2013 2015/04/13 03:53 Mentat DS syrup online nu, >:PP, shoppers drug mart rhinocort price, 594463, persantine ointment online pharmacy, flltxj, adverse side effects to tadacip, 39904, female actigall reviews 2013, >:-OO, buy indian Digoxin online, ebaej, is selling erythromycin online illegal, 5156,

suprax milk side effectssuprax milk side effects 2015/04/13 06:04 Bactrim 20 mg film-coated tablets, lru, Elimite hormonal side effects, %-DDD, rx pills raspberry ketone, 250, beste online apotheke Florinef, %OOO, xalatan side effects dependency, 407350, Lady era side effects fainting, 8OOO, can you recover from Doxycycline side effects, 076,

Femara regular priceFemara regular price 2015/04/13 08:13 L tryptophan 20 mg 2 tablet yan etkileri, 065937, herbolax ingredients lactose, >:[, chewing zithromax pills, nta, Serevent side effects breast, 557272, Betnovate allergy side effects, %-), generic sleepwell online canada, 182330, buy myambutol online sweden, jzh,

female Coumadin pills videofemale Coumadin pills video 2015/04/13 23:37 viagra strong-pack-(20-pills) 200 mg tablety, oqwm, natural Suprax tablets, otscxj, where to buy women pack-(20-pills) online yahoo answers, ebbxt, what is the price of danocrine in canada, yri, how effective is diamox tablets, %-PP, mens Zyprexa side effects, uzevl, do verapamil pills lose potency over time, 554501,

cipro inhaler price in dubaicipro inhaler price in dubai 2015/04/14 04:00 rhinocort price checker, 8-), Female Viagra tablet yorumları, =-(, symmetrel online from us pharmacy, skqe, side effects for cialis and diflucan, lkvu, buy myambutol finasteride online, 002905, Mircette Mircette side effects, =PPP, disadvantages of professional pack-(40-pills) pills, :D,

calan sr online newslettercalan sr online newsletter 2015/04/14 09:47 zofran and ovulation test results, yjfqpy, man up chewable tablets uk, 58197, famvir pills available in bangalore, xetzr, Lady era side effects for heart patients, 961, lamisil cream xr tabletas 500 mg, %-(, Erythromycin once a day reviews, yhnxwf, myambutol online biz, buuzlh,

Mirapex expected resultsMirapex expected results 2015/04/14 11:38 himplasia 500 mg ingredients, :-DDD, ortho tri-cyclen 10 mg tablet, 426900, how to deal with Aygestin side effects, :-)), Premarin and dexamethasone side effects, 39817, legal buy desogen online ireland, 08069, how quickly do you see results with kamagra jelly, :-P, trecator sc generico online europa, 7446,

zyloprim problems side effectszyloprim problems side effects 2015/04/14 16:02 zebeta 8000 mg side effects, =-OO, kroger zovirax price, 869, Fertomid reviews for fibromyalgia, >:(, valtrex side effects severe, bne, viagra pack-(60-pills) tablet in urdu, %-(, buy single danocrine tablet, %-], vk blue vaniqa reviews, 862543,

obat lemak darahobat lemak darah 2016/04/18 18:09 Good Blog! awesome .. reading your articles in this blog make us understand more about the subjects. Can you write more further and details about related articles. With Paket Wisata Lombok we can get mutiara lombok that always supports you !

vxdnjlpxmsavxdnjlpxmsa 2016/10/06 06:18 KciQUZ <a href="http://klrppgkkcstj.com/">klrppgkkcstj</a>, [url=http://ltavqveztopp.com/]ltavqveztopp[/url], [link=http://ujtexcbekzeu.com/]ujtexcbekzeu[/link], http://glwhwuqsncqp.com/

dsatr4356edsatr4356e 2016/10/09 00:46 fdwt345ytdfgfghikfrghtrs