I’ve made a new version of the Ant task for GWT, version 1.1.2. The only change is that when a compile error occurs, a BuildException is thrown and the Ant task fails. Before, an error was just printed, but the build continued. Thanks to Britt Piehler for reporting the bug.
Tech Life of Recht » archive for January, 2007
Ant task for GWT
- January 31st, 2007
- 5:40 pm
More on Haskell
- January 23rd, 2007
- 5:39 pm
Ok, so I’ve managed to write an actual application in Haskell. It’s actually a rewrite of a C program (which I didn’t write myself). Even though it’s a pretty small program (it’s a wrapper for qmail-local), it’s definitely been interesting. I might even go as far as to say thay I understand monads – although I’m not going to attempt to explain them here.
It’s a little uncertain if the program got any better by rewriting it. I pretty much suck at C (way too much time spent in Java), so at least I avoid the segfaults. The Haskell program came in at 89 lines, the C program at 126, and the Haskell program actually has a bunch of extra features.
Anyways, I’m beginning to like Haskell and the way it works. If only the reference api had more examples…
Fun with Haskell
- January 19th, 2007
- 2:02 pm
At JAOO 2006, I attended a session with Erik Meijer on Haskell. The session gave a very quick introduction to Haskell as a very nice functional language, and the enthusiasm of Erik Meijer on the subject only made it more interesting.
So, I've been messing around with Haskell for a while, without producing anything worthwhile - I'm still trying to figure out how to put the language to good use. However, I found a list of Haskell quizzes, derived from Ruby Quiz. Some of these have not yet been solved, so I sat down and began working on Splitting the Loot. After some hours, I suddenly discovered that I have a working solution - somewhat to my surprise.
Anyways, here it is - as it's one of my first Haskell programs, I'm sure there's lots of room for improvement. What it does is basically to find all possible combinations of a list of numbers, and then it tries to combine these combinations in order to find a valid solution:
-
divide :: Integer -> [Integer] -> [(Integer, [Integer])]
-
divide persons vals
-
| toInteger (length vals) <persons = error "Not enough values"
-
| not $ mod (sum vals) persons == 0 = error "Values cannot be divided equally"
-
| otherwise = divide'' persons vals (div (sum vals) persons) [] 1
-
-
divide'' persons vals maxval res cnt
-
| cnt> persons = res
-
| otherwise =
-
let p = permut vals maxval
-
nx = findE p maxval
-
in divide'' persons (deleteFirstsBy (==) vals nx) maxval ((cnt, nx):res) (cnt + 1)
-
-
-
findE [] c = error "Unable to find fitting element"
-
findE xs c
-
| sum (head xs) == c = head xs
-
| otherwise = findE (tail xs) c
-
-
-
uniq [] sorted = reverse sorted
-
uniq xs [] = uniq (tail xs) [head xs]
-
uniq xs sorted
-
| head xs == head sorted = uniq (tail xs) sorted
-
| otherwise = uniq (tail xs) (head xs:sorted)
-
-
-
permut :: [Integer] -> Integer -> [[Integer]]
-
permut nums maxval = permut' nums [] 0 maxval
-
permut' :: [Integer] -> [[Integer]] -> Int -> Integer -> [[Integer]]
-
permut' nums [] _ maxval = permut' nums (map (\x -> [x]) nums) 0 maxval
-
permut' nums xs cnt maxval
-
| cnt + 2> length nums = uniq (sort xs) []
-
| otherwise = permut'
-
nums
-
(xs ++ uniq
-
(sort $
-
foldr (++) []
-
[map (\ ys -> appendIfNecessary x ys nums maxval) xs | x <- nums]
-
)
-
[])
-
(cnt + 1)
-
maxval
-
-
-
appendIfNecessary x xs old maxval
-
| elem x (deleteFirstsBy (==) old xs) = if (sum xs) + x> maxval
-
then xs
-
else x:xs
-
| otherwise = xs
GWT Ant example
- January 10th, 2007
- 11:49 pm
Due to popular demand, I've packed a small example distribution together for GWT Ant and XDoclet. Download it, unpack it, and run ant. It's also an Eclipse project, so you can import it directly in Eclipse.
xfsdump/xfsrestore
- January 5th, 2007
- 7:50 pm
Because I'm going to need this later, and I don't want to forget:
Dump xfs to a remote host:
xfsdump -l0 - /mnt | gzip -c | ssh user@host dd of=/somewhere/backup.dgz
Restore xfs from remote host:
ssh user@host "dd if=/somewhere/backup.dgz" | gunzip -c | xfsrestore - /mnt



