/fpt/ - Functional Programming Thread

Functional programming

Resources:
>Erlang
learnyousomeerlang.com/content
>>Elixir
chimera.labs.oreilly.com/books/1234000001642/index.html
elixir-lang.org/learning.html
>F#
fsharp.org/learn
>Haskell
en.wikibooks.org/wiki/Haskell
0x0.st/pbp.pdf
>Lisps
>>Common Lisp
gigamonkeys.com/book
cs.cmu.edu/~dst/LispBook/book.pdf
Paul Graham's ANSI Common Lisp
On Lisp
Common Lisp Recipes
Land of Lisp
>>Clojure
braveclojure.com/foreword/
The joy of Clojure
>>Scheme
Little Schemer
The Seasoned Schemer
The Scheme Programming Language by Kent Dybvig
Realm of Racket
Lisp in Small Pieces
>OCaml
realworldocaml.org/
ocaml.org/learn/tutorials/
>Scala
Functional Programming in Scala (Chiusano and Bjarnason)
Atomic Scala (Eckel and Marsh)
Programming Scala (Wampler and Payne)
Programming in Scala (Odersky, Spoon and Venners)
>Web languages
>>Elm
guide.elm-lang.org/
>>PureScript
purescript.org/learn/

>Theory
SICP
Essentials of Programming Languages
Practical Foundations for Programming Languages: cs.cmu.edu/~rwh/pfpl.html
How to Design Programs: ccs.neu.edu/home/matthias/HtDP2e/
Art of the Propagator
An Introduction to Functional Programming Through Lambda Calculus

Other urls found in this thread:

livescript.net/.
underscorejs.org/
twitter.com/NSFWRedditImage

Fucking solid. Thanks! Taking the dive into either Haskell or Common Lisp, I need some time to think about it as I only like to focus on a language at a time.

Which functional programming languages do you use Sup Forums?
Do you study category theory?

Do languages I tried to learn count?

LINQ ought to be enough for anybody.

>muh monads
you make me sick

>tried
What do you mean "tried"?

I use C#.
Sell me on functional programming.

Anyone got experience with Clojurescript?
I was gonna use it for my web thing so I don't have to deal with JS (also, macros might come in handy). I have lots of experience with Racket but no experience with clojurescript, and when I initially tried to set it up it seemed like a hassle and a lot of overhead just for a simple script. Is this true? Is it easier than I think?
Right now I'm regrettably leaning towards typescript because it will compile into a .js file with a single command in a makefile

do we have an IRC?

Do or do not, there is no try

LINQ is FP

It's less boilerplate than OOP. But you have to learn it to judge for yourself.
Also those "if it isn't pure it isn't FP" assholes need to shut up, it's fine to be impure and pragmatic every once in a while.

FP doesn't have to be pure, but pure FP is better

Elixir is just a meme amongst Ruby people right?

1. It's fun.
2. It shows you another way you think about a problem, improving your ability to write oop
3. Its more concise than oop.
4. Its faster than oop.

Learning Clojure is not 'pragmatic' in any sense of the word.

>Sell me on functional programming.
Do you use LINQ?

If yes:
Congratulations, you're already programming with some functional elements.

If not:
You're not using C# correctly.

But if I can use linq for areas that are helped by FP and I don't need to use it otherwise, why would I program in nothing but the FP paradigm? Linq is great but I wouldn't want to use a similar system for everything.

This may be me being a retarded babby but pure FP confuses the shit out of me, the concept of OOP is just much more intuitive and easy to work with.

Falling too deep into ~~~~~~PURE ENCAPSULATION INFINITE INHERITANCE GETTERS AND SETTERS INTO INFINITY~~~~~~~ from java is obviously a waste of time but languages like C# seem to get around that.

Good points, especially 2. Any languages you'd recommend me to start with?
Also, how is 4 true? How could it be any faster post-compile? (or do you mean to write)

try F#, there's a tutorial as a VS project template

Karen, nobody fucking cares, go kill yourself you weaboo scum.

What is your favorite ML and why?

>Falling too deep into ~~~~~~PURE ENCAPSULATION INFINITE INHERITANCE GETTERS AND SETTERS INTO INFINITY~~~~~~~ from java is obviously a waste of time but languages like C# seem to get around that.

nigga what kinda fucking hypocrite are you
c# encourages encapsulation everywhere
the only thing c# does better in regards to inheritance is methods being final by default, which is still fucking shit
c# encourages getters and setters a lot more than java, properties even worsen a lot of the negative aspects of getters and setters (now it even looks like a member!)

>PURE ENCAPSULATION INFINITE INHERITANCE GETTERS AND SETTERS INTO INFINITY
But that's what OOP is

If F# used enough by developers ? As M$ is more a C#/shitty VB.Net thing. And is it decent compared to haskell ?

I would normally say having a language on top of js is not worth it... but typescript detects type errors, so it seems alright

it's paid well and there are jobs for it, it can interface with C#


>compared to Haskell
it's nowhere near as good

>why would I program in nothing but the FP paradigm?

You wouldn't.
You shouldn't.

C#'s LINQ is the most accessible, useful, makes-sense-in-the-real-world application of functional programming that exists.

Don't use F# if you're complaining about Microsoft.

F# is no less a product of Microsoft than C# is.

Better to move to C and implement your own functional features, because Haskell is a fucking meme and Scala is shit.

go to bed bill

>c# encourages getters and setters a lot more than java, properties even worsen a lot of the negative aspects of getters and setters (now it even looks like a member!)

If you think that
public string myProperty { get; private set; }

accessed with
string foo = other.myProperty;

is just as easy to write and nonbloated as
private String myProperty;

public String getMyProperty(){
return this.myProperty;
}

accessed with
string foo = other.getMyProperty();


then we'll just have to agree to disagree because you won't ever be able to convince me that they are equal in terms of usability

Haskell is great

bill gates doesn't give a shit about C#, and Microsoft was disgusting under his and Ballmer's direction. Nutella may be a pajeet but they're open-sourcing everything these days

there's even rumors that Mono and the full .NET Framework are going to converge and be open sourced

Volunteer OCaml shill reporting in.

dude, learn FP, I used to hate it but when you grasp it, It will blow your mind.

>mfw finally learned FP

Even though I complain about M$ (calling it M$), I respect their dev tools and C# (but VB.net)

Anyway, why haskell is a fucking meme ?

friend
the problem of getters and setters isn't that it's hard to write them
you fucking autist

Not quite. It's becoming a meme amongst web dev people because Phoenix is a lot saner than the other large web frameworks. They're starting to realize that maybe the object-based approach of Rails and Django isn't the best match for the problem domain. I don't think the really hard core rubyists are in a rush to switch to Elixir. It imposes a lot more discipline on the programmer than Ruby.

I've seen some Erlang devs look into it, too, but Erlang devs are too few to make an impact on the memeosphere.

It's not that they're hard to write, it's that they (specifically within java) bloat the shit out of your files for 0 reason.
There is nothing wrong with accessors.

You're in a FP thread.

90% of their focus is on how succinct it is to write something.

>bloat the shit out of your files
oh no, 0.03 megabytes, whatever will my hard drive do?

>there's even rumors that Mono and the full .NET Framework are going to converge and be open sourced
And what's the profit then?
It's not like I like .NET, but they are alien to any non-Windows environment. What's the point?
Meanwhile, 3 billion devices run Java.

It's less about the size of the file and more about the fact that you either have a big fat tail on your file or you have a bunch of shit in the middle that you have to deal with

3 line getters and setters are ugly, and you can't convince me otherwise. Even if you edit your IDE or text editor to autoformat them as one line, it's still way more than there has to be.

Why are javafags so defensive?

add = (+)
I am doing Functional Programing!

He was clearly not talking about memory, but more on readability/maintainability. Expressing code in fewer line = less error prone and more readable.

Can you explain how web frameworks are sane any way? I usually hack something together myself.

Programming and writing meaningless code are not the same things

>Better to move to C and implement your own functional features
I mean, that's a fine solution if you're a NEET and also barking mad. However, you could also just use OCaml or Standard ML compiled with MLton if you want to avoid Haskell.

>Why are javafags so defensive?
They're used to it. They live in a bloated environment (Eclipse) all day long, writing bloated programs.

>if you want to avoid Haskell
why would you want that?

>There is nothing wrong with accessors.
can you not think of a single reason
ask yourself any of the following questions:
- is it intuitive that an accessor is suddenly very expensive?
- is it intuitive that an accessor changes its api to suddenly throw an exception?
if you can identify something clearly as an accessor as opposed to just a "regular" method, you make fairly strict assumptions about what it does.
these assumptions actually limit the changes you can make to the accessor without caller code unintuitively breaking.
this is worsened with attributes because they completly hide the difference between accessors and members.

I don't know. I thought I'd give a practical suggestion for people who, for whatever reason, consider Haskell "a meme".

>And what's the profit then?

Look at it this way:

I'm a .NET developer. I started using C# because it looked pretty easy to read and straightforward. I've fallen in love with the language over time, and I've started to really take advantage of the features. I know many libraries that help me actually get shit done and make clients/other stakeholders happy because I produce results.

Recently, I decided I needed some cloud services to move some data and also implement some machine learning/cognitive APIs like image recognition. Azure has 10/10 .NET SDKs for all of their services, so guess which cloud platform I used?

Xamarin is now free and open source. Azure has an all-in-one mobile service package that gives you a backing database, an endpoint, and a push-notification broadcaster and they even wrap a ready-to-go solution file that's configured to work with these services. 15 minutes later, I've got an app debugging on my Android phone that actually pushes data to a user account backed by an Azure Active Directory.

You can love or hate Microsoft, and I know I sound shill as fuck right now, but god DAMN they are making great tools easy to work with.

I'm employed and I nearly exclusively Microsoft on-prem and Azure services. Ask me whatever if you want to know how deep the rabbit hole goes.

>expressing implications with =
fucking normie pleb kill yourself

congratulations user-san

>mfw user does a functional programming

>I would normally say having a language on top of js is not worth it
What do you mean by "not worth it"?
Typescript feels like OOP boilerplate shit right now and I'd like to avoid all of that if I can.

It's not even that. Every get/set is a FUNCTION CALL. That means that, whenever you want a value, a call frame has to be made. It's not just code bloat, it affects performance, even if only marginally.

Replace "=" by "is more likely to be" if you want, or is that too hard for your remaining neuron ?

typescript adds a little sanity into javascript

nigga = is a symbol used for equivalence, not implication
were you implying that less error prone and more readable => Expressing code in fewer lines, huh, you dumb piece of shit human waste?
>neuron ?
go fuck yourself

That wouldn't be a major issue if the reason was only a performance hit of such small scale IMO

Why not?

Okay, replace = by => if that helps you sleep better. I wasn't doing math though, and my sentence was understandable enough. Now shit a little and relax.

i fucking hate shitfucks like you that missuse symbols that have been in use for hundreds of years because your fucking middle school tier math knowledge only taught you the equals symbol
fuck you
kill yourself

A web framework (or a set of web libraries designed to work together) contains a lot of code you'd write every time when building a web application from scratch. If you manage many similar projects (e.g., you are a contractor working for several companies), it makes sense to maintain one framework instead of N instances of similar code.

A good "full-size" web framework made by somebody else distills many hours of its developers' professional experience in building web applications into code. What that means in practice is that it encourages sound architectural decisions and prevents you from making the kind of mistakes its developers made in the past. On top of that you don't have to maintain it yourself and hunt for the tons of minor security issues that are the norm in web development.

A big downside is that most of these frameworks are highly dynamic (even relative to the baseline for their host languages). This makes debugging a pain. Additionally, migrating code from one major release, e.g., Rails to another isn't trivial. This is where Phoenix shines by doing a ton at compile time.

>= is a symbol used for equivalence
Equality is not equivalence you dumbass

the problem is, you now have to manage two languages: javascript and the other. so you program in this lang, then you have to compile to js and then use, that's another dependency, and then you might still need js, e.g. if you are doing tests in the browser console and there is an error it will tell you the line in the js file. Basically you have to learn/use the syntax of two languages. The first language I tried that on was CoffeeScript which is intended to make js shorter, adds syntax sugar and fix some design issues. But is it worth it when I could just use js? I'm using js functions anyway, just writing them in a different syntax. I got meme'd hard.
As for typescript, js being dynamically typed really can lead you into problems, detecting type errors could be a big help and their approach to oop seems sane; defining an interface seems simple enough.

somehow I accidentally deleted my mention of CoffeScript's fucking whitespace rules

OK, fair enough. I think I'll stick to what I'm using.
The point about testing in the browser is a good one - live debugging clojurescript by poking it with javascript is probably a nightmare. Other than that I don't really care about extra languages; I've already got like five (jesus) -- Python, Jinja, SQL, HTML, CSS.

But I'm probably going to end up writing a script that auto generates typescript/javascript code since neither languages have macros...

If you're in this thread, CoffeeScript probably isn't going to do much for you but LiveScript may. Look at livescript.net/.

Moreover you can just make them inline to avoid creating the function frame (at least in C++). Hepefully the compiler automatically does this when apropiate.

LiveScript looks like a huge meme, I dislike languages that are primarily flowery syntax and sugar. I write Racket which is mainly about being very straightforward and consistent, rather than being pretty or concise

This is a nice functional library for JavaScript: underscorejs.org/

Why would you write a functional library for a non-functional language?

Alright, got faced with an interesting functional programming problem this week, curious about how people here would choose to solve it if they were trying to do it as functionally as possible. So, I wanted to build a function that took a series of files and return as many as possible while the total size is under a certain amount. What would you do?

Someone earlier mentioned category theory being used in functional programming. How is it used?
t. Someone who knows category theory but no programming

something something monads something something haskell

wow
x = x, check
a = b b = a, check
a = b & b = c => a = c, check

>functional programming problem
no

var muhFiles = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories).Select(x => new FileInfo(x)).Where(x => x.Length < muhSizeInBytes);

>x => new FileInfo(x)
can you not just do
FileInfo
?

It's clearly using the constructor for the FileInfo object, thus the new keyword.

You're welcome to write some autistic extension method that will make this line 3 characters shorter.

OOP + FP is a match made in heaven.

every time you write a struct, define a free function
fileInfo = x => new FileInfo(x);

it will be much more readable

There is literally no OOP in that picture, unless you think method notation = OOP

You could do that if FileInfo() was a method that accepted a string.

This is an object constructor, though, and an object constructor is not a method.

>every time you write a struct
Excuse me?

Whenever you create a new struct type, write a free floating function that constructs it

>a new struct type
:^)

>There is literally no OOP in that line of code that make use of an object constructor, and no less than two other objects and their static methods

So constructors (aka functions that return something) and method syntax (aka functions that accept an additional hidden parameter) are OOP now?

>constructors (aka functions that return something)
This is incorrect. A constructor is not a function.

>method syntax (aka functions that accept an additional hidden parameter)
You have a fundamental misunderstanding of LINQ and what it actually represents.

This is the last response you'll get until you do some research and ask a question that is based on some understanding of what you're talking about.

>A constructor is not a function
Right, because in your particular language it's different, that means it totally doesn't share almost everything in common with what one would call a function.

>You have a fundamental misunderstanding of LINQ and what it actually represents.
I wasn't talking about LINQ

Because you'll have to hack together everything, even write your own libraries for shit you don't want to be writing libraries for.

u d 1 tlk 2 ! ch

How would one write a compiler for a functional language? Are there other systems than lambda calculi usable for such languages?

What part are you confused about?

The part where I can't really see how I would put functions on the stack when calling or returning them from higher order functions like you would do in imperative languages for example.

What do you mean?

Let's say I have something like (ML syntax)
let f g h = function x -> (g (h x))
Now I do a call to a partial binding, how do I return it?

>other system
A stack.