• standard function to zip a list with sequential numbers

    From Pavel@21:1/5 to All on Sun Oct 14 19:32:03 2018
    Is there a standard Haskell function to the effect of

    zip [0..]
    or
    zip [1..]
    ?

    Thank you,
    -Pavel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Pavel on Mon Oct 15 02:55:32 2018
    Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> writes:

    Is there a standard Haskell function to the effect of

    zip [0..]
    or
    zip [1..]
    ?

    I don't know what either that short-hand, nor the wording used in the
    subject ("zip a list with sequential numbers") is supposed to mean.

    If you are fining it hard to specify what you mean, either explain it by
    using some other programming language, or at least give a few examples
    of what you want. If zip [0..] should work, what do you want zip [0..]
    to be?

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Pavel@21:1/5 to Ben Bacarisse on Sun Oct 14 22:47:32 2018
    Ben Bacarisse wrote:
    Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> writes:

    Is there a standard Haskell function to the effect of

    zip [0..]
    or
    zip [1..]
    ?

    I don't know what either that short-hand, nor the wording used in the
    subject ("zip a list with sequential numbers") is supposed to mean.
    To rephrase the question, is there a standard name for a function like
    "nmb" below:

    nmb :: [a] -> [(Int, a)]
    nmb = zip [1..]

    and/or like "nmb0" below:

    nmb0 :: [a] -> [(Int, a)]
    nmb0 = zip [0..]


    If you are fining it hard to specify what you mean, either explain it by using some other programming language, or at least give a few examples
    of what you want. If zip [0..] should work, what do you want zip [0..]
    to be?
    [a] -> [(Int, a)]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to Pavel on Sun Oct 14 20:02:55 2018
    Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> writes:
    [a] -> [(Int, a)]

    Integral n => [a] -> [(n, a)]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Pavel on Mon Oct 15 16:43:34 2018
    Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> writes:
    <snip>
    To rephrase the question, is there a standard name for a function like
    "nmb" below:

    nmb :: [a] -> [(Int, a)]
    nmb = zip [1..]

    Oh I see -- and now your earlier description makes sense! But no there
    isn't a standard name for zip [1..].

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Patrick Roemer@21:1/5 to All on Tue Oct 16 17:41:50 2018
    Responding to Pavel:
    To rephrase the question, is there a standard name for a function like
    "nmb" below:

    nmb :: [a] -> [(Int, a)]
    nmb = zip [1..]

    and/or like "nmb0" below:

    nmb0 :: [a] -> [(Int, a)]
    nmb0 = zip [0..]

    What should it be named? In Scala, nmb0 is zipWithIndex - but that's
    already longer than the Haskell implementation...

    Best regards,
    Patrick

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to Patrick Roemer on Tue Oct 16 10:56:59 2018
    Patrick Roemer <sangamon@netcologne.de> writes:
    What should it be named? In Scala, nmb0 is zipWithIndex - but that's
    already longer than the Haskell implementation...

    In Python it's "enumerate", but in Haskell I don't think a special
    purpose function is needed. "zip [0..]" works perfectly well.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Pavel@21:1/5 to Paul Rubin on Wed Oct 17 01:43:00 2018
    Paul Rubin wrote:
    Patrick Roemer <sangamon@netcologne.de> writes:
    What should it be named? In Scala, nmb0 is zipWithIndex - but that's
    already longer than the Haskell implementation...

    In Python it's "enumerate", but in Haskell I don't think a special
    purpose function is needed. "zip [0..]" works perfectly well.
    Thanks!

    I don't like how it pollutes the code when I need to use it many times in one function; also composition with other functions is even cleaner if it's one word, even if it's long (for readability, 1 token vs 5 means makes lots of difference).

    But it's ok -- just did not want to pollute peoples' brains with a new name for a thing that might have already had a name. I thought of enum[erate] but it seems to be used for different things in Haskell. Somehow never thought of borrowing from Scala -- thanks Patrick for the idea. zipWith0BasedIndex, zipWith1BasedIndex it is now -- haters are welcomed (just kidding).

    -Pavel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)