Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #52980

Re: :Re: My LOOP is ugly

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Paul Rubin <no.email@nospam.invalid>
Newsgroups comp.lang.forth
Subject Re: :Re: My LOOP is ugly
Date Tue, 29 Nov 2016 23:31:10 -0800
Organization A noiseless patient Spider
Lines 31
Message-ID <87eg1t77b5.fsf@nightsong.com> (permalink)
References <o1h2gm$qse$1@gioia.aioe.org> <20161130063555.3d621465@maxa-pc>
Mime-Version 1.0
Content-Type text/plain
Injection-Info mx02.eternal-september.org; posting-host="87eff38ad298ed4202aa26656d0a3ad1"; logging-data="4908"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180XRzwMYzjHT+QOEvBxnYI"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
Cancel-Lock sha1:Z0oTPLHJMsn6K5BD1h/BaAF9jIM= sha1:J/N9okbV+lyznWFkTlYhNIhA9N4=
Xref csiph.com comp.lang.forth:52980

Show key headers only | View raw


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


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