[Haskell-cafe] message passing style like in Haskell?

Gwern Branwen gwern0 at gmail.com
Thu Jun 19 08:29:25 EDT 2008


On 2008.06.19 11:33:56 +0800, jinjing <nfjinjing at gmail.com> scribbled 0.5K characters:
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080619/32e37b85/attachment.bin


More information about the Haskell-Cafe mailing list