Still doesn't work perfectly (outputs characters at the end which should be truncated). Does Haskell classify as an esoteric language?
import Data.Char (chr, ord, isSpace)
dec5, decode :: String -> String
dec5 xs = map (chr . fromInteger) $ reverse $ map (flip rem 256) $ take 4 $ iterate (flip div 256) n
where n = sum $ zipWith (*) (map (85^) $ reverse [0..4]) (map (\c -> toInteger $ ord c - 33) xs)
decode [] = []
decode s | head s == 'z' = (replicate 4 '\0') ++ (decode $ tail s)
| isSpace $ head s = decode $ tail s
| otherwise = (dec5 $ take 5 (s ++ cycle ['u'])) ++ (decode $ drop 5 s)
def decode(text):
r = ''
while text:
b, t, text = 0, text[0:5], text[5:]
while t: b, t = b*85 + ord(t[0]) - 33, t[1:]
r += struct.pack('>I', b)
return r
def encode(text):
r = ''
while text:
b, t, text = '', struct.unpack('>I', text[0:4].ljust(4))[0], text[4:]
while t:
b, t = chr(t % 85 + 33) + b, t / 85
r += b
return r
>>26
Can you please enlighten me as to what that piece of code does?
I'm mostly interested in the Control.Arrow and ***.
Name:
Anonymous2009-05-27 17:03
>>27 (***) :: a b c -> a b' c' -> a (b, b') (c, c')
I think this one is pretty clear.
Consider reading appropriate papers¹ for fuller explanation.
____
¹ http://www.haskell.org/haskellwiki/Research_papers/Monads_and_arrows#Arrows
Name:
Anonymous2009-05-27 17:08
>>28
Ah, does it take two functions which take one argument each and return one value and creates a function which takes a tuple of arguments and returns a tuple of values? Don't beat me up, I never even tried understanding Arrows ;_;
Name:
Anonymous2009-05-27 17:12
>>28
Now that I realized that (***) needs (Arrow a) => a, the type signature finally became clear!
I have still a long way to go if I want to write code like >>26-dono. :(
Name:
Anonymous2009-05-27 17:23
>>29
Read Basic Category Theory for Computer Scientists.