Writing kernel modules in Haskell
Writing kernel modules in Haskell
Posted Sep 27, 2009 7:25 UTC (Sun) by shlomif (guest, #11299)In reply to: Writing kernel modules in Haskell by TomMD
Parent article: Writing kernel modules in Haskell
Essentially, even an elegant dinky "log analyser" that people showed me how to write properly using ghc segfaulted.
On a practical level: this isn't helpful without a version of GHC, platform information, and a copy of the progrma that was "properly written". On a theoretical level: this says nothing about the language.
Here is the Haskell program in all its glory - I lost the original one, but people on #haskell have recreated a mostly equivalent one:
import System.Environment
import Data.List
main = do [infile,outfile] <- System.Environment.getArgs
text <- readFile infile
writeFile outfile . unlines . map (\xs -> (show (length xs)) ++ "\t" ++ head xs) . group . sort . words $ text
This program no longer segfaults (even though I recall it segfaulting), but it consumes 38.3% of my 2.5 GB of RAM (I still remember my first 20 MB hard-disk), and takes a long time to run. On the other hand, the equivalent Perl program consumes less than 2% of my RAM and finishes faster:
#!/usr/bin/perl
use strict;
use warnings;
my %hash;
open my $in, "<", "FreeNode-#perlcafe.log"
or die "Could not open - $!";
while (my $l = <$in>)
{
chomp($l);
foreach my $word (split (/ +/, $l))
{
$hash{$word}++;
}
}
close($in);
open my $out, ">", "analysis-perl.txt"
or die "Could not open for writing - $!";
while (my ($word, $occurs) = each(%hash))
{
print {$out} "$occurs\t$word\n";
}
close($out);
The Lisp program using SBCL also runs adequately.
I'm running it on this file:
$ wc FreeNode-#perlcafe.log 383760 3773752 22564515 FreeNode-#perlcafe.log
As much as I like Haskell, I still think the language has many inherent limitations due to its restrictive design decisionsThere are many design decisions I'd happily question - but I wouldn't call those ones limiting. Which ones are you referring to?
The very strong typing, the lazy-only evaluation, the lack of assignment. All of these are essential cornerstones of Haskell, yet result in under-performing code when put together.
