News for hackers. Stuff that matters.
Re:It never makes sense to use foldl on lists in Haskell (2019) by _ZeD_ on Saturday March 21, 2020 @12:36AM (#22644487)
that's not a linked list problem, it's "passing a mutable object around" problem.

there are immutable non-linked list datastructures (the most obvious one in python are tuples)

Re:It never makes sense to use foldl on lists in Haskell (2019) by toolslive on Saturday March 21, 2020 @06:09AM (#22645601)
They are, but it's shallow:

    >>> x = ([1,2,3,4],"whatever")
    >>> x[0].append('z')
    >>> x
    ([1, 2, 3, 4, 'z'], 'whatever')
And python gives you access to anything:

    >>> def gotcha():
    ...      z = globals()['x']
    ...      z = list(z)
    ...      z.append("I've seen'em do it man!")
    ...      globals()['x'] = tuple(z)
    ... 
    >>> x = (1,2,3,4)
    >>> gotcha()
    >>> x
    (1, 2, 3, 4, "I've seen'em do it man!")
Re:It never makes sense to use foldl on lists in Haskell (2019) by didibus on Saturday March 21, 2020 @05:41PM (#22650426)
It be shallow with a Singly Linked List too no? What inherently makes a Singly Linked List better at addressing this problem if it contains mutable elements?
Re:It never makes sense to use foldl on lists in Haskell (2019) by toolslive on Sunday March 22, 2020 @05:39PM (#22658944)
Typically, in a functional language, values are immutable. So if you cons to a list, you create a new value that has the current list as its tail. Since all lists are immutable, they can be shared and there's no need for a deep copy.

Python is not a functional programming language....

Re:It never makes sense to use foldl on lists in Haskell (2019) by dnautics on Saturday March 21, 2020 @12:44AM (#22644528)
sure but IIRC the performance characteristics of manipulating python tuples ultimately way worse if you need to change the contents of the list, by say, prepending, or trimming, or whatever. This is no fun in python:

   def f(some_tuple):
     part_one = take_the_last_three_parts_of_the_tuple(some_tuple)
     part_two = append_to_self(part_one)
     part_three = tail(part_two)
etc.