Re: [Haskell-cafe] Follow up on 'GroupBy behavior'

2007-05-21 Thread Henning Thielemann

On Sat, 28 Apr 2007, Hans van Thiel wrote:

 Thanks again for the help, and, to follow up, this now does what I
 need..

 -- partitions a list according to an equivalence relation

 partition1 :: (a - a - Bool) - [a] - ([a],[a])
 partition1 eq ls = partition ((head ls) `eq`) ls
 --
 partitionBy :: (a - a - Bool) - [a] - [[a]]
 partitionBy eq [] = []
 partitionBy eq ls =
 (fst x):(partitionBy eq (snd x))  where
  x =  partition1 eq ls

partitionBy is essentially a List.unfoldr

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Follow up on 'GroupBy behavior'

2007-04-28 Thread Hans van Thiel
Thanks again for the help, and, to follow up, this now does what I
need..

-- partitions a list according to an equivalence relation

partition1 :: (a - a - Bool) - [a] - ([a],[a])
partition1 eq ls = partition ((head ls) `eq`) ls 
-- 
partitionBy :: (a - a - Bool) - [a] - [[a]]
partitionBy eq [] = []
partitionBy eq ls = 
(fst x):(partitionBy eq (snd x))  where
 x =  partition1 eq ls

Regards,

Hans van Thiel

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe