Profilo di agentzhHuman & MachineFotoBlogElenchiAltro ![]() | Guida |
|
30 maggio Some Haskell loveI've been reading the ``Types and Programming Languages'' ( TAPL ) book bought from Amazon.com and I've been playing with functional languages. The TAPL book uses OCaml for sample interpreter implementations and I started by learning OCaml in the hope of using it in $work. Sadly OCaml's json-static and dbd-pg/postgresql libraries gave me too much pain to install and OCaml's restricted type system made me rather unhappy. So I turned to Haskell . Well, I should have said ``returned'' ;) The syntax of Haskell is even cleaner than OCaml and its type system is much more powerful. I quickly got familiar with Parsec and monads in general by going through the famous tutorial ``Write yourself a scheme in 48 hours''. Furthermore, the TAPL book's introduction to the lambda-calculus language helped me understand the functional programming paradigms ubiquitous in Haskell. Great. Within just a few days, I came up with a working minisql parser for OpenResty which parses simple SQL select statements using Parsec. Building combinator parsers is really enjoyable. The whole parser is composed by several smaller ones which are in turn built upon even smaller ones and so on. Each combinator parser can also take parameters if necessary because they're essentially Haskell functions after all. The ability to do infinite look-aheads in Parsec gives me a lot of freedom to disambiguate my grammar without much hassles. Moreover, Parsec does not backtrack by default, so the parsing speed is still pretty good. Compared to the old minisql parser written in Perl (via the Parse::Yapp module), the Haskell version is at least 1 order of magnitude faster. Besides, the source of the Haskell one is also shorter and cleaner. In the next few days, I happily mudded with the AST constructed by the parser and built four emitters atop it. These emitters are required by the new version of the OpenResty View API. I successfully used Perl along with its modules Test::Base and IPC::Run3 to build a test scaffold for my Haskell compiler. The test suite is completely declarative and extensible. Surprisingly, I could still use the Haskell Program Coverage ( hpc ) toolchain to obtain a pretty HTML report for the code coverage of the whole test suite driven by Perl. So glad to have such a Devel::Cover equivalent on the Haskell land! The source repository for my Haskell version of minisql compiler is located at http://svn.openfoundry.org/openapi/trunk/haskell/ In
the following journal or two I'd like to share the experience of
optimizing my minisql compiler and making it several times faster. 16 maggio Video for my D2 talk about OpenResty and its nifty appsHere's the video for my D2 talk about OpenResty (well, it's mostly a Chinese talk :P): 07 maggio Client-side web site DIY(Sorry if you can't read Chinese...) 好久没在 blog 上用中文写东西了,我的中国朋友们该抱怨了吧!呵呵. 基于 OpenResty 的纯 JS 应用放哪儿都能跑,呵呵,包括你的桌面或者 U 盘。搁哪跑哪,呵呵。不信试一试: http://blog.agentzh.org/site-binary.tar.gz 我的整个 blog 应用都在这个 tarball 里了。下载到桌面解压后,双击里面的index.html 看效果,呵呵。还可以试试"从本地留言";) 所以放 NCP 还是 facebook 上当然也好使。呵呵。如果未来 web app 都做成这样的就好啦,呵呵。美好的未来。。。畅想中。。。 这种东西有趣的地方在于用户可以直接修改我的网站的展现和功能。所以没有必要让用户从我的主站去同步所谓的"风格"(他们只需要同步数据就可以了,只要对应的 OpenResty API 不发生变化)。 叶姐就是这么分分钟把 http://blog.agentzh.org 网站的风格换成http://eeeeworks.org 那样的。呵呵。谢谢叶姐的工作! 即在本地用一个写字板编辑器或者其他什么源码编辑器"随改随跑"。怎么着都比改PHP 这样的东西来得容易吧?呵呵。况且作为站长,我怎么可能把 PHP 给你呢?就算给了你 PHP,怎么可能让你直接连我的数据库? 在 OpenResty 这样的架构下,网站 DIY 第一次成为可能。即使是像 TiddlyWiki 那样的东西,因为缺乏有效的数据持续和同步,只是一个 toy 而已,不能算是 web site. 类似 GreaseMonkey 那样的插件允许用户通过挂 JavaScript 码的方式 DIY 别人的网站,这也是一种不错的方式,缺点是依赖于 Firefox,很难作为一个独立的网站自己重新发布,而且其本质上也是一种打补丁的方式,DIY 的程度也相当有限,经常还要面临 SearchAll 那样的解析 HTML 和抽取数据的头疼问题(问问任大侠的 GreaseMonkey 使用体验吧!呵呵)。基于 OpenResty 的纯 JS 网站是直接运行在 web service 之上的,所以最终用户和站长在数据展现和网站功能上的机会差不多是均等的。最终用户第一次有了可以把网站做成比站长的版本更炫更酷更强大的机会 :) 我觉得这里没必要把我们的用户都想象成"傻爪级"的。呵呵。傻爪级的用户可以直接访问我的 http://blog.agentzh.org 而不会觉得和常规网站有什么大的区别。我们提供了更多的可能性和更诱人的用户自主空间。 我觉得大家把这里的网站看成桌面应用程序就好了。不要有思维上的定势哦。 当然了,如果一定要从我的主站同步展现的话,确实并不方便。传统的桌面软件的更新也面临同样的问题,呵呵。这是软件分发的概念,也是 DIY 网站的概念。 我非常感激老何最初向我提出这样的理念。我一开始也比较难于接受哦,呵呵。(要怪就怪老何吧!哈哈!) |
|
|