Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Worldyn1737y@LeFlawk It's a good example of the difference between declarative and imperative programming. Imperative: change states and then get a final result. Declarative: "this is what this is". The parameter (x:xs) is a list [] where x is the first element and xs the rest of the list. You take x and say "everything greater is on the right side" and "everything lesser vice versa". So you DECLARE how it is recursively instead of changing what is inside the list recursively. The ++ operator just adds lists together
-
ac123511477yThat's a stupid example to show the why.
From all the things that Haskell has to offer, Monads, ADTs, Typeclasses, ... you show a quicksort -.- -
ac123511477y@disolved Really?
I could understand when someone says that about dynamically typed, prologish pattern matching supporting Erlang, but Haskell? -
disolved5317y@ac1235 It was a purely subjective observation, based on Prolog being my frame of reference for declarative languages. Was it really that hard to believe?
-
Worldyn1737y@ac1235 Good example of declarative and functional programming style. Everything else is awesome too but you gotta start selling from somewhere ;)
-
Worldyn1737y@ac1235 and my learning is a work in progress so haven't gotten to know everything yet 👍
-
disolved5317y@ac1235 if i wrote quicksort in prolog it would look and feel very similar to the example. In k it would not.
Just started learning haskell and if someone wants a 'why' I give you quicksort:
quicksort [] = []
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
where
lesser = filter (< p) xs
greater = filter (>= p) xs
undefined