Skip to content

Instantly share code, notes, and snippets.

@yakkomajuri
Last active July 29, 2020 17:03
Show Gist options
  • Save yakkomajuri/18da6589f60eb490f5912883dbb9e008 to your computer and use it in GitHub Desktop.
Save yakkomajuri/18da6589f60eb490f5912883dbb9e008 to your computer and use it in GitHub Desktop.
(x, y, z) = (4, 5, 6)
(x:xs) = [1, 2, 3, 4]
(x, y) = (4, 5)
@pinselimo
Copy link

List unpacking (second line) should be (x:xs).
The cons in between x and xs are actually a function:

(:) :: a -> [a] -> [a]

and part of the constructors of the list type. (The other being Nil / the empty list / [] )
So (x:xs) "undoes" the last construction step of the linked list to yield an element of the list and whatever the rest of the list constructed until there is.

@yakkomajuri
Copy link
Author

Thanks for that! I've never used Haskell myself so this script was directly copied from the original poster. Will correct it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment