Accompanies Miran Lipovaca's "Learn You a Haskell for Great Good!"
Пікірлер: 12
@samuelwinter25544 жыл бұрын
perfect, this is exactly what I needed thank you. please keep this up for others
@alessandroporfirio19104 жыл бұрын
Thank you for these videos! Great presentation!
@renunciant5 жыл бұрын
What is this sorcery!?? *throws holy water*
@兴宣大院君-h4s8 жыл бұрын
still mind blowing
@TheRaphyz10 жыл бұрын
how do i divide a list by 10 or any other number
@Slacquerr10 жыл бұрын
Probably something like [x / 10 | x
@TheRaphyz10 жыл бұрын
iNuchalHead thanks
@jamma2465 жыл бұрын
I know this comment is 4 years old, but... do this: map (/10) ls where ls is your list. This is more general, since you don't need to edit the definition of your list (and you may not have it in this form in the first place anyway). Here, (/10) is the function, let's call it "f", which takes one number, and divides by 10. So f takes a number and spits out a number. More generally, if you have a function f :: a -> b and you want to apply it instead to every element of a list ls (whose elements are of type a), you use the "map" function to map f over each element of the list. That is, you do: map f ls.
@兴宣大院君-h4s8 жыл бұрын
so you mean python somehow take this idea from Haskell list comprehension
@TerryTWeiss8 жыл бұрын
While languages do borrow from each other, it's usually in the form of features, not concepts. List comprehension is one of the foundational concepts of the functional programming paradigms because, among other things, it allows you to filter without iteration, which requires state. As far as I'm aware, there is no other easy way of filtering. You could probably create a Filter structure that holds a list and a test element "index" and then create a recursive function that tests the current "index"'s value, then creates a new Filter with a list with/without the current element and a new "incremented index." But keep in mind, lists aren't arrays, so there are no indices in the same way; it's dangerous to think about it that way. Python and Haskell, along with any functional language, use list comprehension because lists, along with types, are modeled after sets and set theory. Set theory uses set comprehension to filter sets, especially infinite sets. I strongly recommend learning some basic set theory and discrete math with data structures; I promise it'll strengthen your thinking towards all of this and so much else regarding correctness of programs. :)
@MrCmon1137 жыл бұрын
Sean Xiao I'd say it's simply how it's done in maths. (
@saeedbaig42496 жыл бұрын
Sean Xiao Python's list comprehensions were indeed inspired by Haskell. As the Python site itself states: "List comprehensions and generator expressions (short form: “listcomps” and “genexps”) are a concise notation for such operations, borrowed from the functional programming language Haskell (www.haskell.org/)." docs.python.org/3/howto/functional.html