/fpt/ - Functional Programming Thread

DPT: Previous Thread: >Elixir
chimera.labs.oreilly.com/books/1234000001642/index.html
elixir-lang.org/learning.html
>Elm
guide.elm-lang.org/
>Erlang
learnyousomeerlang.com/content
>F#
fsharp.org/learn
>Haskell
en.wikibooks.org/wiki/Haskell
>Common Lisp
gigamonkeys.com/book
Common Lisp Recipes
Land of Lisp
An Introduction to Functional Programming Through Lambda Calculus
>Clojure
braveclojure.com/foreword/
>Scala
It's shit.
>Scheme
SICP
Essentials of Programming Languages
Art of the Propagator
Little Schemer
The Seasoned Schemer
The Scheme Programming Language by Kent Dybvig
Realm of Racket
Lisp in Small Pieces
>OCaml
realworldocaml.org/

Other urls found in this thread:

ccs.neu.edu/home/matthias/HtDP2e/
cs.stackexchange.com/questions/19577/what-can-idris-not-do-by-giving-up-turing-completeness
en.wikipedia.org/wiki/List_of_programming_languages_by_type#Functional_languages
github.com/haasn/fizzbuzz/blob/master/pattern-matching.hs
github.com/haasn/fizzbuzz/blob/master/cycle.hs
github.com/haasn/fizzbuzz/blob/master/monad-comprehensions.hs
github.com/haasn/fizzbuzz/blob/master/guards.hs
twitter.com/NSFWRedditGif

I use functional programming concepts in languages that support them, like map, reduce, filter instead of for loops. I can't be arsed to use a purely functional language though. I find them unreadable.

I see the recommended books in the OP, before somebody just rells me to read the OP. I am reading SICP, but want something to supplement my learning in Scheme. Which book in the OP would you recommend for learning scheme alongside SICP?

What do you find hard to read?

)))))))))))))))

and have you considered using additional higher order functions?

Use them all the time in Javascript. I lke to generalize any algorithm that involves each member of a collection being processed by letting the user pass in their own function to do said processing.
Even the Javascript spec often does this, which is nice

in other languages i mean

that's mostly just lisp
haskell uses . and $ alot, as well as >>= *> >=> =>> &&& *** ||| etc (you know all these)

which I also find hard to read. I don't even like the way funfunfunction writes javascript to be honest, although his videos are great

>python

def tree_sixty():
print("Good Choice")
functional =True
return functional

def three_four_still_moar():
print("Error Finding Truing Completness")
funtional = False
return funtional

def two_by_two_hands_of_blue():
import sys
print("Fatal Error, Core Dumped!")
sys.exit()


def which_python(language):
case_switch= {
'3.6':tree_sixty,
'3.4':three_four_still_moar,
}
if language[6] == '3':
functional = case_switch[language[6:9]]()
elif language[6] == '2':
two_by_two_hands_of_blue()
else:
"Could Not Locate Item in Memory"
funtional = False
return functional

def is_functional(language):
if 'python' in language:
functional = which_python(language)
else:
"Sorry funtional == False"
functional = False
return functional


def main():
language = input("Please Enter Your Launguage\n>")
funtional = is_functional(language)
print("And The Question Is:\n Your Launguage Is Funtional\n What is,",funtional,"!")

main()

I fucking hate python so much. Ugliest language ever. Get out of here with that cancer

Imperative is better than functional cause you're probably some lazy fuck that doesn't think enough

chomp.gets("is this better")

Task: write the function foo in one line.
you can rewrite the function foo, but it has to produce the same output
f = {
'a.txt': 'R',
'b.py': 'S',
'c.txt': 'R'
}
def foo(f):
g = {}
for x,y in f.items():
g.setdefault(y,[]).append(x)
return g

print foo(f)


output
{'S': ['b.py'], 'R': ['c.txt', 'a.txt']}

Task: write the function foo in a non-cancerous language.
you can rewrite the function foo, but it has to be written in a language that isn't Python

pleb detected

ugly because I'm using lists, with Data.Map or Data.Set it'd be a lot better

Why can't you just use Javascript?
Python was a mistake.

pls respond need recs for scheme books to read with sicp

Scheme isn't FP, and SICP is a meme book. Please leave.

"No."

updated to use Data.Map

invert = foldrWithKey (\k v -> insertWith mappend v [k]) mempty

>scheme isn't FP
OP-sama says otherwise

I just copied the previous OP.
Does Scheme have lambdas?

All you need is fold*, muthafuckaaa

*r

yes it does my dude

>Does Scheme have lambdas?
C# is a functional programming language now?

Scheme is truly multi-paradigm, but prefers a functional style (like Clojure, but unlike Common Lisp).

Scheme IS lambdas.

>Idris etc. aren't turing complete to begin with
Where did this idea come from? I hear it semi-regularly.

This thread is pathetic. It is not about programming. It's just a bunch of computers illiterates and first semesters memeing about whatever they just learned.

A quick search shows that most arguments used here are not original and have been copied from some trendy tech blog or other shit site.

The only real programming questions I have seen so far are from beginners(it's fine to be a beginner btw).

This entire site is shit and I don't know why anyone would regularly come here.

apparently so is ruby.

Your C and V keys must be wearing out by now.

>(fun)ctional thread
>not using emacs key bindings
kek

>HaskLEL is useless and, pure functional and stateless languages are a meme
>Lisp is only used for third class text editors
>SICP is not a good book and this is why it's given away for free
>Anime is shit
>Maki a slut
>C++ is much better than C
>Java is the language of the future
>JS is a good choice for server side
>The best software engineers are indians

>program terminated by stack protector
Is there an easy way to work backwards from a program crash? It's easy in Visual Studio, but I have no idea what to use for C/C++ programs on Linux.

Not entirely

So, if I am interested in learning scheme, would little schemer be the best book to read?

You just got trolled hard.

This is the functional programming thread.
Don't ask about non functional languages.

Use gdb

Hello is this the containment thread for memes?

What is the best way to learn for math that is needed for programming ( calculus, algebra, .... )

>Scheme IS lambdas

But it has set!.

Concrete Mathematics

Unfortunately, this seems to be the case.

See

alright, if I have already taken AP comp sci in HS and have basic ideas about how to make ruby and java programs, should I read "How to Design Programs" or "Little Schemer"? I am interested in learning scheme, but I don't want to just learn the language and not know what to do with it, but I still have basic comp sci knowledge from AP comp sci and other HS comp sci classes. I don't want to just waste my time reading 720 pages of how to design programs.


PLS RESPOND

I thought C was functional.

Seems daft not to just reply to me in the other thread.

>taken AP comp sci in HS
>have basic ideas about how to make ruby and java programs

Read HtDP. Seriously good book.

If a book has more than 100 pages then it's shit.

Man up and get started.

ccs.neu.edu/home/matthias/HtDP2e/

dont' forget, steam game giveaway going on in

It's multiparadigm, but mainly procedural.

People often think procedural and functional are the same.

A procedure is a block of code with a scope, basically.

A function is a rule, that associates an element from a set with an element from another set.

A function also does nothing more than that.


A procedure can for example depend of something that is not it's input. It can change things not internal to it. It can also not have an output at all.

What if I have enough "money" to buy games but I ain't retarded?
btw kys desu senpai

It's not the canonical thread.
Please stay tuned before new thread is created.

K, I will read HtDP, after I read little Schemer.

New thread as it was supposed to be:

{-# LANGUAGE TransformListComp #-}

import GHC.Exts

f = [ ("a.txt", 'R')
, ("b.py", 'S')
, ("c.txt", 'R')
]

foo f = [ (the x, s) | (s,x)

>Where did this idea come from?
Idris requires programs to terminate, and uses a termination checker to ensure this is the case.

Due to the halting problem, it's impossible to write a termination checker that works for all terminating, computable programs - therefore there are some programs which you can't express in Idris. (*)

(*) In practice, of course, there's a way to cheat and bypass the termination checker if you're really sure your program terminates, but it's frowned upon, similar to unsafeCoerce in Haskell

cs.stackexchange.com/questions/19577/what-can-idris-not-do-by-giving-up-turing-completeness

My favourite part is where Edwin Brady asserts that Idris is Turing complete.

I fucked up three threads, hope this is OK.

You need to put this link in the OP:
ccs.neu.edu/home/matthias/HtDP2e/

OK.
This thread will be last.

I would also point out that EoPL is more 'how to construct programming languages' than 'how to construct programs'. The OP seems to imply that it's a good way to learn Scheme.

Haskell btfo yet again

λ f = [('R', "a.txt"), ('S', "b.py"), ('R', "c.txt")]
λ M.fromListWith (++) $ map (fmap pure) f
fromList [('R',["c.txt","a.txt"]),('S',["b.py"])]

That ain't a dict, it ain't in the right order, and it ain't as simple.

?

Kindly remove Erlang, Common Lisp, Clojure, Scala, and Scheme from the OP, as they are not functional programming languages.

Additionally, add ML, Miranda, Idris, Coq, Agda, F*, and Clean.

en.wikipedia.org/wiki/List_of_programming_languages_by_type#Functional_languages

>Functional languages include:
>C++
>C#
>Java
>JavaScript
>Python
>Ruby

>xD it has lambdas so it's functional!!!

>Lisps are not functional programming languages
>the first programming language where functions are first class objects is not a programming language
>language that take 3 clean lines to do what takes dozens in haskell, isn't functional
>the only language with good functional macros isn't a functional language

just because you couldn't find lazy evaluation in the first few pages of the tutorial doesn't mean it ain't a functional language, you haven't spent enough time hacking lisp m8

>coq is a functional language

logic programming at best

F* is not even a programming language in any meaningful sense... was looking into it for work ... but no, it's more obvious to me how to write "code" in Coq.

Elixir is on the OP so maybe I can ask

Why does this work
def date_parts(dates) do
stringdates = String.split dates, "-"
Enum.map stringdates, fn(x) -> String.to_integer x end
end

but this doesn't?

def date_parts(dates) do
String.split dates, "-"
|> Enum.map fn(x) -> String.to_integer x end
end

dates is a string in the form of "2013-12-4"
Shouldn't the latter pass the result of String.split through the pipe to the first argument of Enum.map? It compiles but results in an error.

Update, this works too so the problem wasn't in the pipe
def date_parts(dates) do
String.split(dates, "-")
|> Enum.map fn(x) -> String.to_integer x end
end

Why do I have to call String.split with parentheses if I'm piping it but if I'm not then it doesn't matter?

what does fizzbuzz look like in functional programming code?

(map (l (x) (case (even x) "buzz") (odd x) "fizz")) list-of-nums)

New to programming here. That looks pretty fancy yet wonderful.

1. Won't large programs be hard to debug?
2. Can I do it in C?

>1. Won't large programs be hard to debug?
depends, usually programs don't get that large and actually the FP parts help a ton, lispy sorts because you can package any sort of abstraction in macros and MLy sorts because the typechecker tells you everything you still gotta fix.
>2. Can I do it in C?
Sorry, no. C has function pointers so it meets the most trivial definition of FP (first class functions); but gives you neither a rich type checker nor hygenic macros.

>what is functional.h

Try ocaml if you want to ease into functional, it has pretty good interop with c.

then you can have fun without any nerd
most lisp code is pretty imperative. CL doesn't have first class functions
, is making it think the RHS includes the pipe (so like f x, y |> z is f (x, y |> z)
also this

github.com/haasn/fizzbuzz/blob/master/pattern-matching.hs
github.com/haasn/fizzbuzz/blob/master/cycle.hs
github.com/haasn/fizzbuzz/blob/master/monad-comprehensions.hs
github.com/haasn/fizzbuzz/blob/master/guards.hs
examples

pattern-matching.hs is probably the most obvious and straightforward, and the one closest to the usual functional style

the rest are mostly tricks; cycle.hs is an unusually crafty one that throws imperative programmers for a loop

1. that's absolutely garbage code
2. that's not even a fizzbuzz

>, is making it think the RHS includes the pipe
fuck that makes sense thanks

What's some fun F# or Scala beginner projects to do?

In the same vein as making a python web scraper or something.

Make a Haskell web scraper

I've done that before, I want to explore these languages. That is a good Haskell project though.

bump

There is normal /fpt/, nigger
Let this thread die

This IS /fpt/ you thread splitting fuck

This is NOT /fpt/, since:
>no FP-related OP
>link to /dpt/ is given (no need since /dpt/ iterates faster)
>no Next-level programming thread
>no new resources added though there were marked ones
How the fuck I don't know how /fpt/ looks, if I created all threads before?

The brackets are a lisp reference, the boy is programming related, "next-level" unnecessary

>i created all
you cancerous fuck, you're just mad this wasn't made by you

>you're just mad this wasn't made by you
I listed everything that I don't like in this thread.
Oh, and
>Scala: It's shit
Seriously? Those are listed "resources", not "opinions".
I'll be bumping "the other" thread.

>opinions
An opinion that the majority of /fpt/ agrees on, as you can tell from any discussion we have on it.
You know full well your "reasons" are bullshit, made up to give you the excuse to thread split so you can be the OP.

>majority of /fpt/ agrees on
[citation needed]
What thread is the split, it is bumping this thread.
It's nice that this thread carried /fpt/ on, but it's not /fpt/ since there already exists thread with normal OP.

>install MinGW
werks
>install eclipse
werks
>try Hello World
werks
>download, and fix linker settings for sdl
undefined reference to `SDL_main'
>try same fucking thing in Code::Blocks
it just fucking werks

Do IDE's have a will of their own?

Are you sure it's linked properly?
Linking is usually awkward in IDEs and you need to make sure it's the right build and everything

>Are you sure it's linked properly?
Well, I must be doing something wrong. Maybe I am just retarded.

i don't envy people having to link libraries, it's a fucking pain
are you following a set of instructions?

Move to Linux instead