Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #52980
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: :Re: My LOOP is ugly |
| Date | 2016-11-29 23:31 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <87eg1t77b5.fsf@nightsong.com> (permalink) |
| References | <o1h2gm$qse$1@gioia.aioe.org> <20161130063555.3d621465@maxa-pc> |
Melzzzzz <mel@zzzzz.com> writes:
> Haskell:
> ....
> p2b = let f :: [(a,b)] -> (a,[b])
> f x = foldl (\(a,b) (_,y) -> (a,y:b)) (fst.head $ x,[snd.head $ x]) (tail x)
> in map (\x->(fst $ f x,sort.snd $ f x))
> . groupBy (\x y-> fst x == fst y ) . sort
> ...
{-# LANGUAGE TransformListComp #-}
import GHC.Exts (sortWith, groupWith, the)
import Data.Char (toUpper)
import Data.Function (on)
p2b xs = [ (the a, b) | (a,b) <- xs
, then sortWith by b
, then group by a using groupWith
]
t1 = [('C',3),('A',1),('B',2),('A',2),('C',2)]
t2 = [("bar",44),("Foo",2),("foo",22),("BAR",4)]
main = do
print . p2b $ t1
print . p2b $ [(map toUpper a, b) | (a,b) <- t2]
================================================================
*Main Prelude> main
[('A',[1,2]),('B',[2]),('C',[2,3])]
[("BAR",[4,44]),("FOO",[2,22])]
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
:Re: My LOOP is ugly "Robert L." <No_spamming@noWhere_7073.org> - 2016-11-28 10:56 +0000
Re: :Re: My LOOP is ugly trans <transfire@gmail.com> - 2016-11-28 06:37 -0800
Re: :Re: My LOOP is ugly Melzzzzz <mel@zzzzz.com> - 2016-11-30 06:35 +0100
Re: :Re: My LOOP is ugly Paul Rubin <no.email@nospam.invalid> - 2016-11-29 23:31 -0800
Re: :Re: My LOOP is ugly Melzzzzz <mel@zzzzz.com> - 2016-11-30 08:59 +0100
csiph-web