December 19th, 2007 (01:01 pm)

The semester is over, and I didn't fail my C++ course, which is amazing, since I only did half the homework. I realize that the language isn't intentionally painful, but I remain astounded that anyone would willing choose it for new development. No wonder it sent me running back to Pascal all those years ago.





I've been working through the 99 Prolog problems lately, and was quite surprised to discover myself using the S combinator to solve them. S, defined as



S x y z = x z (y z)

<*>

rotate xs n = uncurry (flip (++)) . (split <*> (mod n . length)) $ xs rnd_permu = rnd_select <*> length

rnd_permu_direct xs = rnd_select xs (length xs)

rotate_direct xs n = back ++ front where (front, back) = split (n `mod` length xs) xs

is provided in Control.Applicative as. The two is has proved useful in so far were problems 19 and 25:The latter is easier to understand. It expands asWhich immediately matches the definition given above. The latter is unnecessarily difficult, and would be better written as:I wouldn't have noticed it at all , but I read Applicative Programming with Effects a while ago, which is what made me finally "get" S.