Liskell docs, finally Thu Feb 22 14:23:26 CET 2007

As the ACM SIGPLAN template gave my Latex document much more space, I decided — instead of writing a separate piece of documentation — to enrich my ILC07 submission with more interesting chapters about meta-programming and the Liskell prelude. This paper is much richer in content as the original (about half the content is new) and it finally starts to explain the mechanisms behind defmacro and how you can use them in the Haskell/Liskell world. So if you are interested in Liskell, the revised paper certainly deserves a second look.


Posted by clemens | Permalink | Categories: Liskell

Pattern guards in Liskell Tue Feb 13 13:21:07 CET 2007

Yes, I'm working on documentation this very moment, but after seeing A missing Haskell feature on Planet Haskell, I was unable to resist. I need my daily dosage of coding.

Here is working Liskell syntax sugar for pattern guards as described by Neil Mitchell.

(defmacro (~= pts)
  `(let (((comp ,pts) True)
         ((comp _) False))
     comp))
It can be used right-away as in:
(all (~= Star _) ([] (Star "x") (Atom)))       -> False
(all (~= Star _) ([] (Star "x") (Star "foo"))) -> True
To give you a brief idea why this works: The function body of defmacro is called with a list (called pts) that is bound to ([] (PSym "Star") (PSym "_")) which is equivalent to [PSym "Star", PSym "_"] written in Haskell syntax. This parse tree part is substituted into the backquoted code template at ,pts, resulting in the parse tree:
(let (((comp (Star _) True))          | let comp (Star _) = True 
      ((comp _)       False))         |     comp _        = False
  comp)                               | in comp
The Haskell equivalent of the generated Liskell parse tree is shown on the right hand side for our Planet Haskell readers. This generated parse tree is the result of the compile-time "~=" macro transformation, and instead of the original (~= Star _) expression the generated parse tree is compiled to object code.

You can compile Star.lsk with "ghc Star.lsk -o Star -main-is Star -package LskPrelude".

(For those who already have a local Liskell branch, please pull the latest changes and redo ./darcs-all get. I moved the LskPrelude into a separate new core package. Also I vastly simplified the parse tree type, so the Liskell paper is not correct anymore wrt this.)


Posted by clemens | Permalink | Categories: Liskell

QT RLE: The perfect screencast codec Thu Feb 8 13:56:24 CET 2007

Last week, I promised Liskell documentation. I intended to introduce the basic concepts by screencasts, simply because screencasts are easy to produce and to consume. However, after a few sample runs I ended up with 1.2 gigabytes of MPEG4 data. Too much.

The Screencast codec showdown elects the Animation codec as the best codec for screencasts. Animation is a run-length encoder also known as qtrle. Unfortunately ffmpeg, the codec library of mplayer, was only able to decode qtrle, and I found it very cumbersome to use Windows Quicktime to produce my files. So, I wrote my own encoder for ffmpeg.

With this encoder, the PrologDemo.flv screencast I posted last week is compressed from 100mb to 15mb. That's an 85% improvement. Definately, thumbs up.

QT RLE encoder is diffed against today's subversion. The encoder works lossless and is able to produce RGB24 or RGB555 output. For the moment, RGB24 is default, because RGB555 requires a patch to the quicktime container encoder. (Reimar Döffinger produced this patch 15 minutes after I mentioned a problem with the quicktime encoder on #ffmpeg. Awesome.)

To produce screencasts, get the latest ffmpeg svn, apply the movenc.c patch and the qtrle encoder patch, and compile/use it:

./configure --enable-gpl --enable-x11grab --enable-faad --enable-faac
make
./ffmpeg -vcodec qtrle -vd x11:0+0,0 -pix_fmt rgb555 -r 10 -g 300 \
         -s 1280x1024 -acodec aac -ad /dev/dsp output.mov
A few remarks about the ffmpeg options:
  • Replace "-s 1280x1024" with your screen resolution. Screencasts are usually ok at 1024x768.
  • If you want an RGB24 video, drop "-pix_fmt rgb555" or change it to "-pix_fmt rgb24".
  • "-r 10" sets the frame rate per second. 10fps should be enough for a screencast.
  • "-g 300" sets the group size. This instructs the encoder to produce a key frame every 300 frames. With 10fps, this gives you a seekable stream point every 30 seconds.
If your screencast is still too big, try to raise the group size, lower the frame rate and/or lower the screen resolution.


Posted by clemens | Permalink