Haskell 2d: List comprehensions

  Рет қаралды 28,079

Peter Drake

Peter Drake

Күн бұрын

Accompanies Miran Lipovaca's "Learn You a Haskell for Great Good!"

Пікірлер: 12
@samuelwinter2554
@samuelwinter2554 4 жыл бұрын
perfect, this is exactly what I needed thank you. please keep this up for others
@alessandroporfirio1910
@alessandroporfirio1910 4 жыл бұрын
Thank you for these videos! Great presentation!
@renunciant
@renunciant 5 жыл бұрын
What is this sorcery!?? *throws holy water*
@兴宣大院君-h4s
@兴宣大院君-h4s 8 жыл бұрын
still mind blowing
@TheRaphyz
@TheRaphyz 10 жыл бұрын
how do i divide a list by 10 or any other number
@Slacquerr
@Slacquerr 10 жыл бұрын
Probably something like [x / 10 | x
@TheRaphyz
@TheRaphyz 10 жыл бұрын
iNuchalHead thanks
@jamma246
@jamma246 5 жыл бұрын
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.
@兴宣大院君-h4s
@兴宣大院君-h4s 8 жыл бұрын
so you mean python somehow take this idea from Haskell list comprehension
@TerryTWeiss
@TerryTWeiss 8 жыл бұрын
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. :)
@MrCmon113
@MrCmon113 7 жыл бұрын
Sean Xiao I'd say it's simply how it's done in maths. (
@saeedbaig4249
@saeedbaig4249 6 жыл бұрын
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
Haskell 2c: Lists
8:12
Peter Drake
Рет қаралды 39 М.
Functional Programming & Haskell - Computerphile
9:19
Computerphile
Рет қаралды 678 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
Haskell 6b: Lambdas and folds
10:07
Peter Drake
Рет қаралды 31 М.
How to read Haskell code (in 7 minutes)
6:51
peppidesu
Рет қаралды 80 М.
Adventure with Types in Haskell - Simon Peyton Jones (Lecture 1)
1:33:37
Excel Dynamic Search Box Tutorial | Find Anything | Multi-Column Search
14:17
Rebekah Oster - Excel Power Up
Рет қаралды 64 М.
Haskell 3: Types and typeclasses
6:18
Peter Drake
Рет қаралды 36 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН