Is functional programming a meme?

Is functional programming a meme?

Attached: 1200px-Haskell-Logo.svg.png (1200x847, 15K)

Other urls found in this thread:

youtube.com/watch?v=RqvCNb7fKsg
github.com/funkia/list
en.wikipedia.org/wiki/Map_(higher-order_function)
archive.rebeccablacktech.com/g/thread/65434622/#65445498
themonadreader.files.wordpress.com/2014/04/fizzbuzz.pdf
github.com/twilson63/todo-fp/blob/master/src/pages/todos/index.js
rosettacode.org/wiki/Universal_Turing_machine#C
twitter.com/NSFWRedditVideo

youtube.com/watch?v=RqvCNb7fKsg

Pure functional programming is art. It is practically useless, but can be very aesthetic. Developing complex projects with FP takes too much time and effort , it's not really worth it unless you have infinite resources. However, major languages adapt functional concepts, so you can have the best of both worlds.

>haskell's famous sieve of eratosthenes isn't a true sieve of eratosthenes
>haskell's famous pretty quicksort is an inefficient implementation of quicksort

Why is C not functional programming? You do everything with functions
What is functional programming if not programming with functions

Attached: 1523389993036.jpg (455x400, 57K)

functional is opposed to procedural
in practice it means no for loops, no dealing with iterators, map, reduce, filter, divide & conquer, etc.

I'm not sure but I remember that we ranked C as procedural programming.
Contrary to procedural there's object-oriented.

I'm not impressed

Because C is not functional in a mathematical aspect. In a pure functional language, side effects are eliminated. For example, C has a ++ operator, however functional languages are declarative, so if you assign a value to a variable, it won't change. It doesn't make sense in a mathematical way to change the value of a variable.

for (int i = 0; i < 3; i++) {
printf "Herro wolrd/n";
}

How you do this in Haskell?

Attached: 1524761048387.jpg (300x168, 7K)

C/C++ are literally the only languages you SHOULD know, and lastly, follow up on Python when you have the former learned. If you decided to learn anything else, I'm sorry but you are a complete nigger chimpanzee

I don't think so.

Haskell is getting dangerously close to actually being used. The compiler continues to get better, and it's being actively worked on with large features, like a new internal compiler language and dependent types.

That's just haskell though. At my current job I was hired almost specifically because I've done a lot of functional programming. These days in Javascript / front-end world, the functional style is preferred because it produces very few bugs while being easily testable.

After awhile, things like this:
class Num {
_number = 0;
constructor(num) {
_number = num;
}
addOne() { _number = _number + 1 }
getNum { return _number }
}

start to look absolutely insane.

I've had great success pushing composition, never using for-loops, and always returning a new data structure.

mapM_ (\_ -> putStrLn "hello world") [1..3]

How do you avoid for-loops?

[].map everything

The memory allocator has a huge overhead because it is not functional to modify things inplace. Edits must be done as an edited copy.

This sounds extremely inefficient, because map allocates space for a new array to store the results.

>what is replicateM_

Where's the call to do it 3 times?

Linear types partly solve this

But that's wrong. Your program prints out
hello world
hello world
hello world

but his program prints out
Herro wolrd
Herro wolrd
Herro wolrd

It is inefficient, but generally we've never run into performance issues. I've only had to replace a map with a for loop once for performance, and that was with like an 18,000 item array. The browsers / v8 engine is good at cleaning up. Not 100% sure how it is on memory, but things like github.com/funkia/list exist which are functional and can be even faster than the native list.

Yes it is.

C is imperative.

Imperative is the step by step process to get to something. e.g. How do I get from A to B? I do C.

Functional is defining how something is. e.g. Getting from A to B will always be C.

In imperative programming something like this would be common place:
y = 2
x = y + 3
x = 2 + 3
x = 5
But if you add the following:
x = 5 + 1
5 = 6
It doesn't make sense. Functional programming solves this issue. The function add_two(3) will always return 5 and never 6.

It's first year CS.
en.wikipedia.org/wiki/Map_(higher-order_function)

Easily the worst explanation I've ever seen.

why would anyone want to type this?

replicateM_ 3 $ putStrLn "hello world"

This is better

>Developing complex projects with FP takes too much time and effort, it's not really worth it unless you have infinite resources
I wrote a 6000 line haskell client-server project for my bachelor thesis and I disagree with this. Haskell is mature enough and there is a wide variety of libraries to choose from.
The problem is that FP is unpopular and, as a result, most developers lack the discipline required to write FP code effectively. I believe that this is related with the fact that many developers are predominantly computer-centric, as opposed to math-centric. C is a very computer-centric language, meaning that C code operates in a way similar to how a computer internally works: imperative, mutable state, distinction between value and reference, objects/memory allocations have lifetimes. On the other hand, FP is very math-centric. It's very similar to how mathematics work: declarative, immutable state, no distinction between reference and value, no lifetimes.
Of course, neither paradigm is superior to the other. You have to choose the right tool for the task. I'm happy to see that most math-centric developers that I meet know a thing or two about functional programming.
There is a language that is both strongly computer-centric and strongly math-centric and it is Rust.

true facts, I couldn't remember wtf the name of that was. I looked up "repeat" like a dork on hoogle. thx

Haskell requires a lot of time to be learned whether you used Lisp or C before

The only language I know is haskell
What can I pick up easily that's employable? Clojure?

>functional programmers are Reddit-tier memers who are impressed by their language being able to pass functions to functions
Yeah, seems about right.

>lazily executed
IT'S NON-STRICT YOU FUCKWIT

I don't know what difference it makes though.

javascript

Computer engineering is useless

Consider the entire thing is the development of binary computers. Binary computers don't have to be the end-all be-all. Computer engineering knowledge, that is, things like boolean algebra, adders, ALUs, OS protection rings, MMUs, CPU design, logic gates... all this stuff is useful of course but could become deprecated. ALGORITHM DESIGN however is ETERNAL and not dependent on specific technologies we develop. Functional programming languages are the best paradigm because everything else is highly dependent on the technicalities of how our computers work. Functional langs are naturally more high level and go through more abstraction, but that's honestly fine for the sake of theoretical purity, surface cleanliness, and portability through possibly hundreds of years or more.

Scala is the most demanded in my area.

drugs, the post

Strictness is about semantics, laziness is the actual method of evaluation
The strictness analyzer causes many expressions to be evaluated eagerly without affecting semantics, that's why you say non-strict instead of lazy, the former is always correct

Algorithm can get deprecated too. Look at quantum computers and quantum algorithms. A lot of encryption algorithms will get deprecated because of quantum computers. Also, algorithms are designed heavily exploit the architecture they run on. For example, imagine that computers didn't have random-access memory. All the algorithms that use look-up tables wouldn't have been invented if this was the case.

It's a meme. Most people using them would be better off using a different language. Don't get me wrong, functional languages have merits but most of the interest in them is from evangelism than encountering problems in other languages.

>i've assigned my variable a value of 6 now instead of 5
>this means 5=6
okay...

how do you fizzbuzz functionally then?

archive.rebeccablacktech.com/g/thread/65434622/#65445498

it hurts to look at
why

Not him, but he does have a point, although he doesn't explain it properly. The thing is that "=" operator is a lie. It doesn't mean "is equal to" but "is assigned in this moment".
int x = 5;
x = 6;

Obviously 5 = x = 6 is false. However we can
var 5 >>= \x -> x =: 6

and everything is fine.

Linear types for Haskell when? I know there was a proposal.

they'll be practically deprecated but they'll still "work"

fizzbuzz :: Int -> String
fizzbuzz 101 = []
fizzbuzz x
|mod x 15 = "FizzBuzz " ++ fizzbuzz x +1
|mod x 3 = "Fizz " ++ fizzbuzz x +1
|mod x 5 = "Buzz " ++ fizzbuzz x +1
|otherwise = show x ++ fizzbuzz x +1

You write a paper about it
themonadreader.files.wordpress.com/2014/04/fizzbuzz.pdf

forgot the ==0 part oh well

There's already a patched GHC that supports linear types. I don't know if and when the changes will be merged.

what an absolute meme

that guy is way too smart to write real code, he must write pseudocode with triple bars and conjunctions to avoid dirtying his hands.

Functional programming is a paradigm; you could use it in virtually any programming language. Functional programming languages are supposed to make it easier to use the functional paradigm.

>FP takes too much time and effort , it's not really worth it unless you have infinite resources.
what on earth are you talking about? If you ask literally any company using FP in production, they all say they use it for the exact opposite reason of what you're saying. They use it because it's more efficient and easier to manage when you have limited resources. I have to question whether you've ever worked on a non-trivial FP project before if you're saying this, because it literally makes it easier to maintain large shit with fewer developers. It has a higher learning curve if you're not used to FP of course, but that's a one-time cost, not an ongoing maintenance issue.

Watch any talks about companies using FP languages in production, and you'll see that often the reason they use it is because the teams assigned to take on certain projects are small and/or limited in a lot of ways. The haskell team at fb isn't particularly large, nor is the clojure team at amazon for example. There are exceptions of course, like jane street and jet.com, who both use FP practically everywhere. But ultimately, what really drives the point home and validates this outlook to some extent, is the fact that virtually every language in the industry is adopting FP features, because big companies and teams of developers are demanding it to make their codebases more maintainable (just look at how Google maintained its Guava library long before java started incorporating functional features).

Lazily-executed = normal order instead of applicative order. This is just a difference in how the interpreter runs. Normal order is typically less efficient, and gets very complicated with more complicated functions. They're both useful in certain circumstances.

here is my small-brain version
fizzBuzz x =
let threeDivisible = x `mod` 3 == 0
fiveDivisible = x `mod` 5 == 0

fizzBuzz' True False = "fizz"
fizzBuzz' False True = "buzz"
fizzBuzz' True True = "fizzbuzz"
fizzBuzz' False False = show x
in
fizzBuzz' threeDivisible fiveDivisible

main = do
putStrLn . show $ map fizzBuzz [1..100]

Love user, love....

Attached: received_148719379275011.jpg (1440x2560, 183K)

functional programming is the perfect form of the solution any problem, object oriented is a garbage compromise, and imperative programming is pure sewage

>There is a language that is both strongly computer-centric and strongly math-centric and it is Rust
>Rust
Kek

Pure functional is slightly harder to write, but easier to maintain, since local reasoning is possible.
The reason the TTD memes came about, was that noone wants to touch code where state lives scattered across a million objects.

How does it feel that all your pure perfect FP code runs on an imperative machine where everything is global state?

For industrial programming, yes. OOP has proven that it's the safest and most reliable way of doing this.

For niche programming like scientific programming, it's not. There is as little boilerplate as possible between theory and practice, so it's perfect in this usage. Hence why LISPs dominates AI programming and R dominates data science, but if you were to use the language to write an OS, it'd be a complete disaster.

It's fine. The imperative machine, like the sewers, can be hidden from view.
No need to shit on the street, pajeet.

What the fuck does that even mean? My intel chip will be deprecated but it will still work.....

If I'm a plumber shouldn't I have some knowledge of how the sewing system works?

>sewing system
But yeah, when doing functional you still need some knowledge of the underlying machine. You should know that calling a constructor makes memory allocation that at some time will perhaps be freed by the garbage collector and you need to know that the stack isn't unlimited. But you don't have to think about it every time you make new line.

if there was such a thing as enterprise grade functional programming, this would be it

Do you happen to know good functional style library/projects made in JavaScript I could take a look at the code?

github.com/twilson63/todo-fp/blob/master/src/pages/todos/index.js

this is a nice example. using ramda (my favorite library -- it's like underscore, but functional) + recompose + react + lots of stateless functional components

Because C is modeled after the Turing machine, and not after the Lambda Calculus.

It's only useful in practice if you understand the overhead behind all functions and can write it without being terribly inefficient.

>gives a bunch of very accurate Swedish sentence building skills and then ends the video by saying "I have basically just written english all along". What a tool. Hfeflflfof sir. Hfeflflfof!

>C
It's not even modeled after the Turing machine, it's just comfier assembly.

..and assembly is just comfier machine code..

..whichi is just a comfy way to use sequential circuits..

..which is just for sissies as well , because real men use combinational circuits and remeber the states in their head..


Anyway, it's not about the level of abstraction, it's about the way you abstract things. If you define true=1 and false=0 you're A HERETIC SCUMBAG and halfway at the turing machine.

The only acceptable way is to define true=λab.a and false=λab.b and work your way up from here..

Attached: y_combinator.jpg (640x480, 35K)

I just wanted to say that C isn't really close to Turing machine.

But you can build one..

>rosettacode.org/wiki/Universal_Turing_machine#C

Or do you mean the finite space?

>>[1..3]

Functions in C are not functions, they are subroutines.

FP has its place, but pure, stateless FP is almost never the best choice. Not to mention that anything useful eventually NEEDS side effects, since reading and writing from external sources are side effects.

Learning about it and studying lambda calculus in particular is certainly beneficial to broaden your horizons, but you shouldn't wank over it and worship it as the only paradigm worth being used.

Almost every real world programming problem is best solved with a combination of techniques/paradigms/languages. Don't needlessly restrict yourself.

Yes. Nobody uses it

building a large lazy string like this is very inefficient. lists are control structures, not data
also you forget to parenthesize (x+1), and there's no separator between the numbers
5/10

not bad
8/10

The correct answer was
fizzbuzz x
| mod x 15 == 0 = "FizzBuzz"
| mod x 3 == 0 = "Fizz"
| mod x 5 == 0 = "Buzz"
| otherwise = show x

main = mapM_ (putStrLn . fizzbuzz) [1..100]

It's the language paradigm of choice for high functioning autists.

It also requires godlike skills to program efficiently in, because trying to predict what the compiler is going to turn your code into and intuiting how code will flow is so much harder. Then again, who writes efficient code any more nowadays?

> if you were to use the language to write an OS, it'd be a complete disaster.
HURR WHAT AM LISP MACHINES?? Sure they lost commercially, but not because you can't write a lovely OS with LISP

How come nobody talks about OCaml? I know of at least one extremely high performance company whose full infrastructure is written in OCaml

No, but Logical Programming is.

What functional programming really is
>lambdas
>monads
>c and c++ code that does fast shit

What functional programming languages do
>Make shit way more complicated than lambdas
>refuse to use fast shit from c and c++
>most of the time don't use monads cause they added in more than lambdas

Does any FP language apart from Haskell even use monads?
I never encountered them in Scheme.

Don't hate me, but I really like to look at Haskell Programms and adapt them for Ruby.
It's a lot of fun..

class Integer
def fizzbuzz
self % 15 == 0 ? "FizzBuzz" :
self % 3 == 0 ? "Fizz" :
self % 5 == 0 ? "Buzz" :
self
end
end

puts (1..100) . map &:fizzbuzz

No.
If you need proof, every language is slowly converging towards lisp, and every language is adding some form of lambdas and closures.

* Scheme

How is fp more maintainable? Is it because there are so many people who suck at documenting their work?

It seems like a cheap alternative that possibly/likely cuts on efficiency

Scheme is a lisp, well done user, gold star.

OOP is easier to maintain when data structures change, but more complex whne you want to change behaviour.

FP is easier to maintain when the behaviour changes, but more complex when you change data structures.


This is especially true when you have complex processes (i.e concurrent events) where it's a real relieve when you have immutable structures.

>wiki.c2.com/?IsSchemeLisp

aren't monads pretty worthless? just a layer of shit-you-wouldn't-need if the language decided so. The "nobody gets it at first" seems more like "nobody understand why they exist - ever"

Regular object oriented programming with first class functions is the way to go (C#, slightly worse: Java).

Haskell takes the math a littel bit too serious..

But generally monads aren't difficult.
They are simply tortillas at the endofunctors of mongoids, where's the problem?

But seriously, it's basically the same as Java's boxing/unboxing ("int" vs "Integer").

C is stupid, and what C calls functions are better understood as procedures.