
On 2008.06.19 11:33:56 +0800, jinjing
Hi guys,
This is my second attempt to learn Haskell :)
Any way here's the code:
module Dot where import Prelude hiding ( (.) )
(.) :: a -> (a -> b) -> b a . f = f a
infixl 9 .
So for example, 99 questions: Problem 10 (*) Run-length encoding of a list.
comparing:
encode xs = map (\x -> (length x,head x)) (group xs)
to
encode xs = xs.group.map token where token x = (x.length, x.head)
I found starting with data and working my way to a solution seems to be easier to think with, or maybe it's just me ...
What is your thought?
Jinjing
http://cgi.cse.unsw.edu.au/~dons/blog/2007/07 sez: encode = map (length &&& head) . group decode = concatMap (uncurry replicate) for a different twist on your approach using arrows. -- gwern Kerry W NAVSVS industrial Parvus NAVWAN ISM 8182 NRC Reno