Xen and Fedora

Submitted by TomMD on Wed, 03/19/2008 - 7:36pm.

So this is a little off topic for sequence.complete.org, but I'm going to document some of my run-ins with Xen and Fedora here. Also, I am looking for somewhere more generic to move my blog - any suggestions? EDIT: I just decided to go with wordpress, so you can find my ramblings at tommd.wordpress.com

Installing Xen
I had some issues with installing/using Xen from source. I mudded the waters at the start by trying out various versions / packagings (Fedora Xen package, xen-3.0.4-testing, xen-3.2-testing, xen-3.2.0) and I discovered that:

  1. 'make clean' will remove ALL xen kernels (rm /boot/*xen*). This eliminated a perfecting fine xen-3.0.4 install when I was screwing around with 3.2-testing.
  2. 'make clean' missed some python scripts - causing the xm tool funky behavior till I manually cleaned /usr/lib and reinstalled Xen.
  3. Fedoras Xen package is fine (currently a Xen-3.1 derivative) , unless you have special desires like ACM - in which case you certainly need to use a source distribution. Good work Fedora!

Installing Fedora PVMs
Using the virt-install tool (package: python-virtinst) it is dead simple to install stable Fedora distros (of coarse the GUI tool, virt-manager, exists too):

# virt-install -n F8 -r 512 --vcpus=1 -f /var/lib/xen/images/F8.img \
--vnc -p -b virbr0 -l "http://mirrors.kernel.org/fedora/releases/8/Fedora/i386/os/"

But be sure to enable packet forwarding by adding to your /etc/sysctl.conf. If you don't, you'll find the packets won't get forwarded from your bridge (xenbr0 or virbr0) to your network.

# Controls IP packet forwarding
net.ipv4.ip_forward = 1

Or use sysctl or directly alter /proc/sys/net/ipv4/ip_forwarding, if you are rustic like me.

Dealing with Rawhide
I figured I could be a rawhide tester by running it as a DomU - I was right and wrong.

  1. Rawhide can not act as Dom0. It seem that, due to the PV_Ops task, Fedora 9 is not intended as Dom0 - Fedora 8 and 10 will fill the host role.
  2. Rawhide doesn't currently run as a paravirtual machine (PVM - a type of DomU). I've reported bug 437217, which has an obvious fix, and bug 437706, which is where I'm at now.

Do arrows, monads, monad transformers clash when a large app needs libraries which use each of these?

Submitted by metaperl on Mon, 02/25/2008 - 12:59pm.

Now for my question

from my neophyte perspective, Clean has a single easy-to-use mechanism for state maintenance - uniqueness typing.

Haskell has monads.

But then it also has arrows now.

And so there are two XML products, one based on arrows and one based monads.

When one is developing a large project in Haskell, what does one do if certain libraries are done in arrows and others in monads and you need to use both? And what about monad-transformers? Is that not yet a 3rd complication?

A Java programmer only has objects to handle any concept. So the idea of one library doing one thing and another doing another does not come up.

So, is there a difficulty in large application development because of the clashing advanced functional metaphors of arrow, monad, monad transformer?

Let's face it. There are very few large-scale products shipped in Haskell. Period. I dont know how good that is. or why that is.

I suppose Galois is happy with haskell, but the lack of large useable apps make you wonder if something like what I mention is getting in the way.

About my level and interest haskell

I have been through SJT's book. Been through the Haskell Road. Been through Sethi's "Algorithms". Like Bird and Wadler's intro to FP.

Now, I first got interested in Haskell in 2003. I love haskell. It is profoundly elegant. I never quite got over the hump into making it useful... 8 years as a Perl developer spoils you. But as a Perl developer, I think very functionally and studying Haskell has helped me immensely. But i always run back to my crutches when the game gets tight.

QWERTY makes a comeback on Dvorak

Submitted by metaperl on Fri, 12/14/2007 - 7:17am.

If you take a look at handheld computers and/or PDAs, GPSs, etc. you will note that the keys are quite close together.

This is where QWERTY is a good thing. It was a typing system designed to keep subsequent keystrokes from being very close to each other.

This is great for these tiny keyboards... with dvorak, I imagine your fingers would be bumping into each other.

My Haskell Emacs configuration

Submitted by mrd on Fri, 11/02/2007 - 12:18pm.

I generally like some of the features that come with haskell-mode for Emacs. But I cannot reconcile my style with that of the "smart" indentation mode. I'm not too keen on the default indentation function of Emacs either, at least, not for Haskell code. I use the basic tab-to-tab-stop function but it needs a little tweaking to bring it down to reasonable levels of indentation.

Tabs should never be used.

(setq-default indent-tabs-mode nil)

I like align-regexp, a neat tool from Emacs 22.

(global-set-key (kbd "C-x a r") 'align-regexp)

Basic haskell-mode loading:

(add-to-list 'load-path "path/to/haskell-mode")
(load-library "haskell-site-file")
(add-to-list 'auto-mode-alist '("\\.hs\\'" . haskell-mode))

My indentation settings. I wrote my own "newline and indent" function which brings any code you split onto the newline back up to the same indentation level it was at previously.

(remove-hook 'haskell-mode-hook 'turn-on-haskell-indent)
;; Just use tab-stop indentation, 2-space tabs
(add-hook 'haskell-mode-hook
(lambda ()
(setq indent-line-function 'tab-to-tab-stop)
(setq tab-stop-list
(loop for i from 2 upto 120 by 2 collect i))
(local-set-key (kbd "RET") 'newline-and-indent-relative))
(defun newline-and-indent-relative ()
(indent-to-column (save-excursion
(forward-line -1)

And just in case you were wondering how to tweak syntax highlighting colors in your .emacs, here's what I do:

(set-face-bold-p 'font-lock-builtin-face nil)
(set-face-bold-p 'font-lock-comment-face nil)
(set-face-bold-p 'font-lock-function-name-face nil)
(set-face-bold-p 'font-lock-keyword-face nil)
(set-face-bold-p 'font-lock-variable-name-face nil)
(set-face-foreground 'font-lock-builtin-face "cyan")
(set-face-foreground 'font-lock-comment-face "pale green")
(set-face-foreground 'font-lock-function-name-face "green")
(set-face-foreground 'font-lock-variable-name-face "pale green")

I think it's fairly self-explanatory. You can play around with the values and find what you like. M-x list-colors-display is a handy tool to list out all the possible colors along with examples.

darcs freeze

Submitted by jmuk on Tue, 06/13/2006 - 11:26pm.

... in a limited situation.

I will import the HTTP library into my haskellnet repository. However, the importing process of darcs freezes.

Probably, this occurs because both repositories have same directory name, Network. HTTP contains a patch to create Network directory (adddir Network), but this directory already exists in haskellnet library. So darcs are confused.

Certainly, I can easily import the HTTP files directly (not through darcs pull). But, in such case, there will be two problems.
- I lost all of the history of the works for HTTP
- If some patches are send to either library, it is difficult and annoying to send the paches to other library.

I have an idea to deal with this problem -- modifying the patch manually. But darcs allows such modification?

preface: to develop HaskellNet...

Submitted by jmuk on Sun, 06/04/2006 - 11:38am.


I'd like to develop a library for haskell with Google summer of code. See SoC page or haskell.org page for more detail.

HaskellNet is a library for network protocols such as SMTP, POP3, IMAP, HTTP, FTP and so on. In this blog, I will write my thought about HaskellNet design and implementation and report the progress of my project.

I write it in advance: I have no confidence for my English skill, so I will make trivial (grammatical) mistakes. In fact, this blog is also for my English training. If you find some mistakes or unnatural phrases, feel free to point them out.

If not, any comments are welcome.


Submitted by Greg Buchholz on Thu, 10/20/2005 - 2:23pm.

Over on comp.lang.lisp we have someone trying to use Haskell for a little symbolic differentiation problem. Since it doesn't even compile, I thought I'd throw my hat in the ring and clean it up a little (Is there a better way to display snippets on this site? I had to use <pre> tags instead of <code> tags)...

infixl 5 :+
infixl 6 :*
data Exp = Num Integer
         | Var Sym
         | Exp :+ Exp
         | Exp :* Exp deriving (Eq,Show)

data Sym = X | Y deriving (Eq,Show)

main = do let exp = (Num 4 :* Var X :* Var X)
          let deriv = d exp X
          putStrLn $ "Original expression : " ++ (show exp)
          putStrLn $ "Derivative : " ++ (show $ simplify deriv)
          putStrLn $ "Derivative evaluated at X=10 : "
                     ++ (show $ eval (d exp X) [(X,10)])

--take the derivative...
d (Num n)  x = Num 0
d (Var y)  x | x==y      = Num 1
             | otherwise = Num 0 
d (f :+ g) x = (d f x) :+ (d g x)
d (f :* g) x = (d f x) :* g :+ f :* (d g x)

--evaluate an Exp...
eval (Num x) env = x
eval (Var x) env = case (lookup x env) of 
                        (Just n)  -> n
                        (Nothing) -> error $ "no variable "++(show x)++" in env"
eval (x :+ y) env = eval x env + eval y env
eval (x :* y) env = eval x env * eval y env

--a few algebraic simplification rules
simp (x :+ y) | x == y = simp (Num 2):*x
simp ((Num 0) :+ x) = simp x
simp (x :+ (Num 0)) = simp x
simp ((Num x) :+ (Num y)) = Num (x+y)
simp (x :+ y) = simp x :+ simp y
simp ((Num 0) :* x) = Num 0
simp (x :* (Num 0)) = Num 0
simp ((Num 1) :* x) = simp x
simp (x :* (Num 1)) = simp x
simp ((Num x) :* (Num y)) = Num (x*y)
simp (x :* y) = simp x :* simp y
simp x = x

--apply simplification rules until the expression doesn't change anymore
simplify x = let a = iterate simp x
                 fix = dropWhile (\(c,d)->c/=d) $ zip a (tail a)
             in (fst.head) fix

instance Read a, given a Parsec parser

Submitted by dtlin on Fri, 10/07/2005 - 1:46pm.

Given any type a, for which there exists an parsecRead :: Parser a, the instance Read a can be defined really easily.
But I didn't find it in the Parsec docs.  Maybe I wasn't looking hard enough.

{- This code is dedicated to the public domain. -}
import Text.ParserCombinators.Parsec
class ParsecRead a where
  parsecRead :: Parser a
instance (ParsecRead a) => Read a where
  readsPrec _ = either (const []) id . parse parsecRead' "" where
    parsecRead' = do a <- parsecRead
                     rest <- getInput
                     return [(a, rest)]

It could be used like this:
data Foo = Foo
instance ParsecRead Foo where
  parsecRead = string "foo" >> return Foo
-- instance Read Foo

Defining instance Read a requires GHC's -fallow-undecidable-instances, though.
Well, you could always just repeat the readsPrec definition for everything you want, but it seems to me that this should exist just because it's convenient and common enough.

Someone help me. The Haskell Road is Calling...

Submitted by metaperl on Fri, 10/07/2005 - 5:13am.

For some reason, I keep picking up "The Haskell Road to Logic, Maths and Programming"

All my life I have avoided proofs and mathematics, but perhaps now is the moment to meet my Maker. I keep going back to this book.

For some reason, it is infectious. A beginner introduction to how thought is structured. A beginner introduction to what math is all about.

I had been wondering what I was going to do with Haskell once I finished learning it. I am a Perl professional by trade and even though some interplay has been going on, I never really knew why I was learning Haskell. I just liked the conciseness and elegance of the language and the mathematical purity.

The most important thing is to have passion behind what you do. If I want to go deeper into math for math's sake, then so be it... no need to artificially create projects for myself. Just enjoy haskell and math. It is a very very good fit.

dealing out 5 hands of cards, each containing 5 cards

Submitted by metaperl on Sun, 09/04/2005 - 10:22pm.

I helped someone out in #haskell with the problem stated in the subject by writing the code below. I'm a bit rusty (and never was very good) at Haskell, so any pointers on how to improve the code I supplied to him are appreciated.

cards = [1..52]

dropAmount = [ d*5 | d <- [0 .. 4 ] ]

hand cards = map (\d -> (take 5 $ drop d cards)) dropAmount