Posts

Debugging Haskell: LFG, AVM → DAG

Image
A few days ago I had to do some debugging in Haskell while writing a function to draw directed acyclic graphs of attribute value matrices from LFG F-structures. UnsafePerformIO was great help there. I did most of this during a machine translation lecture given by Kurt Eberle of lingenio . Here are the debugging functions: deb1 :: Show a ⇒ a → a deb1 a = unsafePerformIO (print a >> return a) deb2 :: Show a ⇒ String → a → a deb2 msg a = unsafePerformIO (putStrLn (((msg ++) . show) a) >> return a) deb3 :: (Show a, Show b) ⇒ (a → Bool) → b → a → a deb3 p b a = unsafePerformIO $ esc p b a where esc p b a | p a = putStr ((show b) ++ (show a)) >> return a | otherwise = return a cond = (== "^OBL") dobj = deb3 cond And here is how I used them in context: core :: Integer → String → [(Integer,String)] → AVM → (String,[(Integer,String)],Integer) core i s ls (M att (A val)) = (s ++ x i ++ " [label=\"" ++ dobj s att ++ "\...

mono string hash code collisions

After reading the following blog post by David R. MacIver about hash code collisions in java strings: For reasons you either know about by now or don’t care about, I was curious as to how well String’s hashCode was distributed (I suspected the answer was “not very”). I ran a few quick experiments to verify this. For your amusement, here is a list of all hash collisions between alphanumeric strings of size 2: http://www.drmaciver.com/collisions.txt and here is a list of all which don’t collide with any others http://www.drmaciver.com/noncolliding.txt Some statistics: There are 3844 alphanumeric strings of size 2. Of these 3570 collide with at least one other string. That is, 274 of these strings (or about 7% of them) *don’t* collide with something else. Oh well. It’s a good thing no one would be stupid enough to rely on hashCode to distinguish the contents of two objects. I tested things with .NET 3.5 and MONO 1.9.1 on a 32-bit Windows Vista: running on .NET 3.5: 3844 two-char string...

Mono 1.9 binary package for Solaris 10/x86

Jonel Rienton has provided a Mono 1.9.0 binary package for Solaris 10/x86 ! I am thankful to him for his kindness^_^!

okitsune 狐

Image
I am working on a new project called: okitsune 狐 - it is going to be a simple theorem prover of sorts for logic students. Okitsune is being written in Haskell and open for contributions: okitsune.sourceforge.net code sample: analytic tableaux for propositional logic

Haskell and F#: Language Design

Image
After watching a taste of Haskell by Simon Peyton-Jones and having a look at A History of Haskell: being lazy with class , I am left with some open questions regarding the design of F#: Why is F# not lazy?: What is the advantage of eagerness? Is there a point in encapsulating side-effectful operations in monads while programming in F#? IO Monads etc.? #light // Sample F# IO Monad : OSCON Haskell Video Part 2 type IO<'a> = IO of 'a // get: unit -> IO<string> let get () = IO(read_line ()) // put: string -> IO<unit> let put x = IO(print_string x) // bind.e: IO<'a> -> 'a // bind: IO<'a> -> ('a -> IO<'b>) -> IO<'b> let bind (x:IO<'a>) (y:('a -> IO<'b>)) = let e (IO(a)) = a in y (e x) let (>>=) = bind // gp: unit -> IO<unit> let gp () = get () >>= put gp () Why did the F# team chose ML and OCaml over Haskell? I hope someone from the F# team...

Segmenter Compiler: Benihime, 紅姫

Image
Code generation subsystem of Benihime is undergoing major refactoring with two goals: extensive use of generics in the public API and maximum amount of code reuse. With major concern about the performance of the current regex implementation in Mono (1.2.6) , I wish I already had enough time to spare today to submit a standards-compliant regex compiler replacement as a contribution. I hope Benihime to become one in the near future.

Expert F#

On a completely unrelated note, I have been reading Expert F# and I must admit that I begin to like the language. If you are someone who is going to learn his first programming language or just feel like adding a new one to your arsenal, I strongly recommend having a look at F# – with interesting mix of paradigms, terse syntax and strong type inference, it is sure to be a pure delight to work with.