Search code examples
pythonhaskelliterable-unpacking

Is there a Haskell equivalent way of iterable unpacking like in Python?


I wonder if it is possible to create variables from an iterable of things in Haskell. I found this when I search for it but I couldn't adapt it for my case. Maybe it's not possible or I'm missing something since I'm a beginner. Basically, I'm wondering if something like this is possible in Haskell:

>>> list_of_lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> a, b, c = list_of_lists
>>> print(a)
[1, 2, 3]

Solution

  • ghci> list_of_lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
    ghci> [a,b,c] = list_of_lists
    ghci> print a
    [1,2,3]