From: Brian Mitchell Date: 2006-04-21T07:31:37+09:00 Subject: Re: Converting IP range to array of IP's On 4/20/06, Tom Moertel wrote: > Brian Mitchell wrote: > > Other's solutions should work great but just for fun and enlightenment > > I wrote my own little implementation of a simple list comprehension in > > Haskell .... > > You might also find fun in what 'sequence' does in the List monad: > > Prelude> :t sequence > sequence :: (Monad m) => [m a] -> m [a] > > Prelude> mapM_ print $ sequence [[192], [168], [0,1], [1..10]] > [192,168,0,1] > [192,168,0,2] > [192,168,0,3] > [192,168,0,4] > [192,168,0,5] > [192,168,0,6] > [192,168,0,7] > [192,168,0,8] > [192,168,0,9] > [192,168,0,10] > [192,168,1,1] > [192,168,1,2] > [192,168,1,3] > [192,168,1,4] > [192,168,1,5] > [192,168,1,6] > [192,168,1,7] > [192,168,1,8] > [192,168,1,9] > [192,168,1,10] Thanks. I was already aware of that but didn't think of naming my example method that name. Good to have that pointed out to me every once in a while (for some reason I have not gotten used to using monadic functions on lists yet). After writing this I think it might be fun to write a monadic extension library and maybe add a collection of monad transformers. This would bring a very powerful set of tools to Ruby. Maybe someone can come up with some nice DSL like Haskell's do notation. I haven't found one yet. Brian.