Functional programming thread

In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. It is a declarative programming paradigm, which means programming is done with expressions or declarations instead of statements. In functional code, the output value of a function depends only on the arguments that are passed to the function, so calling a function f twice with the same value for an argument x produces the same result f(x) each time; this is in contrast to procedures depending on a local or global state, which may produce different results at different times when called with the same arguments but a different program state. Eliminating side effects, i.e., changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behavior of a program, which is one of the key motivations for the development of functional programming.

Functional programming languages have largely been emphasized in academia rather than in commercial software development. However, prominent programming languages that support functional programming such as Common Lisp, Scheme, Clojure, Wolfram Language (also known as Mathematica), Racket, Erlang, OCaml, Haskell, and F# have been used in industrial and commercial applications by a wide variety of organizations. JavaScript, one of the world's most widely distributed languages,has the properties of an untyped functional language, in addition to imperative and object-oriented paradigms. Functional programming is also supported in some domain-specific programming languages like R (statistics), J, K and Q from Kx Systems(financial analysis), XQuery/XSLT (XML), and Opal. Widespread domain-specific declarative languages like SQL and Lex/Yacc use some elements of functional programming, especially in eschewing mutable values.

Other urls found in this thread:

youtube.com/watch?v=OyfBQmvr2Hc
golang.org/doc/codewalk/functions/
fsharpforfunandprofit.com/
github.com/rust-lang/rfcs/issues/271
twitter.com/NSFWRedditImage

>/fpt/
ayyy are we back

looks like /fpt/ is more active than ever

Scala is disgusting

Linear types when

it's jvm

>JavaScript, one of the world's most widely distributed languages,has the properties of an untyped functional language
NO FUCK YOU OP
DON'T GIVE THEM AMMUNITION
END THE "JS IS FP" MEME NOW
REEEEEEEEEEEEEEEEEE
FUCKING WEBLETS APPROPRIATING MY CULTURE
GET OUT OF MY FUCKING PARADIGM
YOU ARE NOT FUNCTIONAL

I like the pair in lisp. With just SICP and a shit language I was able to write something. Thanks caaddr.

What's up? You don't like mutable and immutable versions of the same thing all over the place?

JavaScript's C-like syntax, including curly braces and the clunky for statement, makes it appear to be an ordinary procedural language. This is misleading because JavaScript has more in common with functional languages like Lisp or Scheme than with C or Java. It has arrays instead of lists and objects instead of property lists. Functions are first class. It has closures. You get lambdas without having to balance all those parens.

...

Functional programming has long been popular in academia, but with few industrial applications. However, recently several prominent functional programming languages have been used in commercial or industrial systems. For example, the Erlang programming language, which was developed by the Swedish company Ericsson in the late 1980s, was originally used to implement fault-tolerant telecommunications systems. It has since become popular for building a range of applications at companies such as T-Mobile, Nortel, Facebook, Électricité de France and WhatsApp. The Scheme dialect of Lisp was used as the basis for several applications on early Apple Macintosh computers, and has more recently been applied to problems such as training simulation software and telescope control. OCaml, which was introduced in the mid-1990s, has seen commercial use in areas such as financial analysis, driver verification, industrial robot programming, and static analysis of embedded software. Haskell, though initially intended as a research language, has also been applied by a range of companies, in areas such as aerospace systems, hardware design, and web programming.

Other functional programming languages that have seen use in industry include Scala, F#, (both being functional-OO hybrids with support for both purely functional and imperative programming) Wolfram Language, Lisp, Standard ML and Clojure.

Scala sucks
F# has a terribly limited type system

This thread might work better if instead of namefagging quotes barely anybody will read, you would post as anonymous and bring up interesting topics.That would be a good thread.

You could also just make a shitpost that will bring people into the thread to tell that shitposter he's wrong. That might be a good thread if the shitpost doesn't swallow 300 posts.

Just a thought, do as you want.

Functional programming is for basement dwelling NEETs without a real job.

fuck, marry, kill

OOP is for wagecucks

t. functional contractor

Come back to me when Haskell can do physically based rendering of 3D environments at a pace that isn't slow as death.

>implying a private construction company won't build better cheaper roads faster where the demand for them is highest

Marry Haskell, it's pure.

Fuck Scala, the JVM makes me feel dirty.

Kill OCaml, I caught it in bed with facebook.

Finally making >$2k a month from my f# side project. Feelsgoodman.

Which should I learn?

t. C++/Python brainlet

Since functional programming is stateless, would this guy like it?

You should learn to think for yourself

Too hard for neckbeard brainlets here. They like trash like c and writing fizzbuzzes in imperative style. No Scala/clojure/elixir/scheme here.

Which functional programming language is the most used by industry? I.e. which one will allow me to get a job the most easily. I want to learn that one. I have a feeling it's Erlang? Pls and thanks for help.

Id say Elixir, Elixir is a huge improvement in syntax over Erlang so it feels like a regular scripting language. It borrowed a lot of ideas from Clojure in how it abstracts over lists. And it adds strings instead of just the ridiculous and unusable byte arrays of Erlang.

I'm enjoying Elixir so far but miss the type safety as I now tend to pepper my code with structs, specs, and doctests just to be sure everything is sane (I tend to use Haskell and play with Idris). Other than that I would say it's great, currently translating lisp programs to elixir to get the hang of things plus OTP (might write a lisp repl with phoenix).

Not sure if I should write a macro for chaining the below having it act like a failure monad or just use exceptions and let it die.
defmodule Lambda do
def eval({:lambda, x, body}, env) do
fn(arg) ->
eval(body, fn(y) -> if (x == y), do: arg, else: env.(y) end)
end
end

def eval({rator, rand}, env) do
(eval(rator, env)).(eval(rand, env))
end

def eval(x, env) when is_atom x do
env.(x)
end

def eval(x) do
case eval(x, fn(_) -> :error end) do
:error -> {:error, :undefined}
success -> {:ok, success}
end
end
end

Haskell. jk but I wish it waa the case

I'm going through Learn You a Haskell... at the moment as an introduction. Is it a good resource? It's recommending the interactive shell but some of the examples it gives are not being accepted by ghci.

Also it's really tested my knowledge of mathematics so far. I learnt set theory basics years ago but it isn't at the forefront of my mind.

Scheme --> Common Lisp


Clojure

Clojure, Scala, Elixir, mostly with a few places now picking up Elm for frontend.

Why start with Scheme?

It's one of the easier languages to pickup and one of the most powerful plus there's no end to good books, lectures, and papers for it.

Watch this and you'll see just some of the things one can do with it
youtube.com/watch?v=OyfBQmvr2Hc

I used lyah to get into Haskell, I liked it. It's not too technical while not leaving the important stuff out. I remember sometimes having had problems with examples not compiling, I don't remember the reasons though.

Absolutely not. It's horribly outdated. Try haskellbook.

Javascript is my favorite functional language.

How does a non wagecuck programmer make money for living annon?

All the useful aspects of functional programming have already been cannibalized and inserted into more general programming languages. Heavy immutable focus, lazy loading, tail-end recursion, and (of course) lambdas.

All you really have left is an autistic shitfit any time anyone mentions the word "class."

type class

Elaborate please.
I think it gives you the freedom to spaghetti all over the place, but if you are a good developer it gives you very powerful tools, such as implicits.
You can write pure code in scala, it's all up to you.
And again, Scala is great for Big Data.

> Python (Data science, Django), Javascript (React, Vue web), C/C++ (micro controllers) brainlet here.

Is Rust capable of functional *style* programming?
Is there popular (as in getting a job) fp lang out there that can solve variety of problems?

Rust as some essential support for FP (pattern matching, closures, iterators, tail call recursion), but we still don't have good Monad or lenses libraries.

The most popular FP language that can also get you a job is Scala.

That's why typescript destroys Javascript

Putting a pie inside of some shit does not improve the shit.

I've been wondering for some time now, what is the purpose of the lenses library in Haskell?

>but we still don't have good Monad or lenses libraries
Wouldn't it be necessary to intoduce higher-kinded types to the language before getting there? The basic functionality is already there for concrete types (.andthen(…)), but it's currently not possible to abstract over that uezs.

it's like an abstraction on fields, so for instance

person.name

with lens, you can have something like "name" which is a first class (it's a regular value) field manipulator, you can do stuff like

person^.name.first.initial
-- access the initial of the first part of the name of person

change the name
(name .~ someothername) person

use monadstate
name .= someothername

etc, it can do other things, e.g. traversals (multiple fields in one), prisms (potential fields), isos, etc

Very useful, thank you very much.

The Lenses library in Haskell is horribly overengineered in my opinion. Have been using microlens and I'm quite happy with it.

I learned haskell in college. I never wanted to kill myself that much since then.

almost certainly

i also think something like zoom needs to be built into monadstate because otherwise it doesn't play very nicely

why is data immutability important? serious question

Immutability makes it harder to make certain types of errors in your program. It also makes it much easier to test your code.

There are no side effects, you dont need to understand how the programs' components interact with each other, you need only to understand the single component.
Less prone to error, since every time you call the function f passing value x you will always have y as a result, not true for OO languages like java that rely on internal status of the class.

Haskell hobbyist on suicide watch

>Functional programming is also supported
Well, if you're going that way then Python, Ruby, Java, Scala, Go, Rust and lately even MATLAB also support functional programming though they don't endorse it.

How does Go support functional programming?

>tfw you're a professional OCaml developer.

Directly from Go's top-tier documentation: golang.org/doc/codewalk/functions/

Weblets are irritating but the quote is correct.
>has the properties
Most languages right now are a mix and thus have properties of various paradigms.

Either by working as a contractor or turning your own sideproject into something that brings in enough money to live on.

Learn doing FP in Python.

Erlang should be pretty high but checking job offers it seems Haskell tops.

>Elixir
I don't think web development is industry,

Haskell is not a systems language.
If you want FP and system programming, use Rust. It's basically a more advanced OCaml.

dumb frogposter

>You can write pure code in scala, it's all up to you.
So it's no better than TypeScript. Scala is deprecated.

Scala has a lot more support on FP than TypeScript.
It's not haskell tier and i won't even try to defend that, but it has niche and use cases where it excelles and it's better than Haskell.
At the current moment Scala is the best option if you want to go big data.

F#. Go to fsharpforfunandprofit.com/ and watch Scott's talks to get a good taste of FP and F#.

Don't listen to You can write in a functional style on every language, but you will have a very hard time *learning* FP that way.

>seething Haskell hobbyist mad at Elixir professionals

Elixir seems fine but I've seen it used nowhere besides web development

Last time I checked Rust didn't have tail call optimization. Are you sure about that?

>but it has niche and use cases where it excelles and it's better than Haskell.
If you HAVE TO interface directly with the JVM && have Scala programmers available && (gotta ship fast || huge Scala codebase already).

Other than that, no. For JVM work either Frege or Idris are far better languages; even Clojure is at least on par with Scala due to the sheer greatness of their ecosystem and how write-only Scala can be.

It seems is not implemented yet.

github.com/rust-lang/rfcs/issues/271

Cam someone explain the benefits of lambda calculus? I know the basics of what it is, just not how or why it's used.

fuck Haskell, that bitch is crazy
marry OCaml, she's wife material
kill Scala, anything related to the jvm needs to die

Inductive expr (T : Type) : Type :=
| value : T -> expr T
| func : forall U : Type, expr (U -> T) -> expr U -> expr T.
Check expr.
Check value.
Check func.
Arguments value {_} _.
Arguments func {_ _} _ _.

Fixpoint eval (T : Type) (e : expr T) : T :=
match e with
| value x => x
| func f x => (eval _ f) (eval _ x)
end.
Check eval.
Arguments eval {_} _.

Definition eint : nat -> expr nat := fun n => value n.
Check eint.

Definition eplus : expr nat -> expr nat -> expr nat :=
fun e1 e2 => func (func (value plus) e1) e2.
Check eplus.

Definition emult : expr nat -> expr nat -> expr nat :=
fun e1 e2 => func (func (value mult) e1) e2.
Check emult.

Notation "x + y" := (eplus x y).

Notation "x * y" := (emult x y).

Notation "2" := (eint 2).

Notation "3" := (eint 3).

Eval compute in eval (2 * 3 + 2).

>lambda calculus
Best tool to factorize code.

I learned haskell's basics, not more, I really should catch up soon.
What is haskell's native support on parallelism?
As a scala developer I've always loved parallel's collections.

now can someone translate what this fucking nerd just said?

Haskell is fucking great at parallelism and concurrency.
It sorta uses lightweight threads like Erlang.
You can spawn two parallel computations by using the `par` operator.

it's the most simple and refined essence of functions

Which part? I said two things. The first is a stupid coq code, the second is the explanation of why fp is best paradigm.

With programming in general, what is more important: CPU, RAM, GPU?
How does each factor tie into the others?
If you could upgrade your system in one of these aspects, which would it be and why?

you sound like a lifer programmer

>a lifer programmer
A what?

>coqsucker doesn't know what a lifer programmer is

Very interesting.

Is this a "what should I upgrade guys" post in /fpt/?

No. This is a 'what should I look for in my next machine because I'm making a start in programming' post.
Answer my original question pls user

It doesn't seem like fpls get a lot of use on "real" projects, though I believe emacs was written in lisp. Any good examples of commercial programs written in a fpl?

This is very vaguely connected to programming in overall and functional programming isn't any more connected to it than any other programming and it doesn't really belong to this thread but I'll tell you what I think since you asked so nicely.

You actually don't need anything special for programming (especially since you said you're making a start so I guess you won't have projects with hundreds of thousands of lines just now). 2010 cum-stained Thinkpad is enough. Compilation times depend heavily on the CPU but you won't have problems with it until you try to compile very big projects. More important is having a machine that actually can run programs you write if you want to make some 3D graphics or something (older integrated GPUs will struggle with 3D graphics). If you want to learn programming in general you'll write undemanding programs and if they run slow on your computer it means you're doing it wrong. If you want to get into 'muh machine learning' then you'll certainly want a good deal of RAM but I don't think there is much programming going on actually.

ROSAMUNDE
FRAG DOCH NICHT ERST DIE MAMA

The core of Emacs is ELisp interpreter that is written in C. Most of what is considered Emacs is ELisp indeed. Jane Street uses OCaml. I've heard of Haskell being used in banks for critical parts (critical in correctness view point). There is an editor written in Haskell named Yi, but it isn't a commercial project and isn't really mature and I don't know if it's even being actively developed.

What is fftw?

By the way, nice quads.

Thank you for the info. I tried finding a more relevant board but gave up after not seeing a programming general thread.
>inb4 somebody links me to it and proves i'm lazy/a dumbass

So the general takeaway is go for CPU performance with 4-8gb ram since nothing special is needed and basically pay to attention to the graphics?
Thx user xo

dysfunctional programming > functional programming

>clunky for statement
you mean standard and correct for statement

Generally, you can just wait longer for your program to execute if you have a slower CPU, but if you run out of RAM, you're fucked for good. On the other hand, you shouldn't really write programs that run out of RAM to begin with, maybe only for experimental purposes. GPU is definitely the least important though, unless you specifically want to write programs that use it.

don't die /fpt/!

Java programmer here, where do I start learning functional programming?