[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/fpt/ - Functional Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 306
Thread images: 18

File: 1480974118479.png (518KB, 974x974px) Image search: [Google]
1480974118479.png
518KB, 974x974px
DPT: >>58208426
Previous Thread: >>58174033

>Elixir
http://chimera.labs.oreilly.com/books/1234000001642/index.html
http://elixir-lang.org/learning.html
>Elm
https://guide.elm-lang.org/
>Erlang
http://learnyousomeerlang.com/content
>F#
http://fsharp.org/learn
>Haskell
https://en.wikibooks.org/wiki/Haskell
>Common Lisp
http://gigamonkeys.com/book
Common Lisp Recipes
Land of Lisp
An Introduction to Functional Programming Through Lambda Calculus
>Clojure
http://www.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
https://realworldocaml.org/
>>
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?
>>
>>58212117
What do you find hard to read?
>>
>>58212128
)))))))))))))))
>>
>>58212117
>>58212128
and have you considered using additional higher order functions?
>>
>>58212146
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
>>
>>58212146
in other languages i mean

>>58212144
that's mostly just lisp
haskell uses . and $ alot, as well as >>= *> >=> =>> <|> &&& *** ||| etc (you know all these)
>>
>>58212181
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
>>
>>58212017
>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()
>>
>>58212243
I fucking hate python so much. Ugliest language ever. Get out of here with that cancer
>>
>>58212017
Imperative is better than functional cause you're probably some lazy fuck that doesn't think enough
>>
>>58212263

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']}
>>
>>58212362
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
>>
>>58212413
pleb detected
>>
>>58212413

>>58212410

ugly because I'm using lists, with Data.Map or Data.Set it'd be a lot better
>>
>>58212432
>>58212430
Why can't you just use Javascript?
Python was a mistake.
>>
>>58212124
pls respond need recs for scheme books to read with sicp
>>
>>58212491
Scheme isn't FP, and SICP is a meme book. Please leave.
>>
>>58212516
"No."
>>
>>58212413
>>58212432

updated to use Data.Map

invert = foldrWithKey (\k v -> insertWith mappend v [k]) mempty
>>
>>58212516
>scheme isn't FP
OP-sama says otherwise
>>
>>58212600
I just copied the previous OP.
Does Scheme have lambdas?
>>
>>58212117
All you need is fold*, muthafuckaaa

*r
>>
>>58212619
yes it does my dude
>>
>>58212619
>Does Scheme have lambdas?
C# is a functional programming language now?
>>
>>58212600
Scheme is truly multi-paradigm, but prefers a functional style (like Clojure, but unlike Common Lisp).

Scheme IS lambdas.
>>
>>58209434
>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.
>>
>>58212695
apparently so is ruby.
>>
>>58212758
Your C and V keys must be wearing out by now.
>>
>>58212805
>(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.
>>
>>58212695
Not entirely
>>
So, if I am interested in learning scheme, would little schemer be the best book to read?
>>
>>58212840
You just got trolled hard.
>>
>>58212881
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, .... )
>>
>>58212709
>Scheme IS lambdas

But it has set!.
>>
>>58213032
Concrete Mathematics
>>
>>58213027
Unfortunately, this seems to be the case.
>>
>>58213059
See >>58213136
>>
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
>>
>>58212977
I thought C was functional.
>>
>>58213208
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.
>>
>>58213208
If a book has more than 100 pages then it's shit.
>>
>>58213208
Man up and get started.

http://www.ccs.neu.edu/home/matthias/HtDP2e/
>>
dont' forget, steam game giveaway going on in >>58210842
>>
>>58213273
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.
>>
>>58213364
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.
>>
>>58213325
>>58213277
K, I will read HtDP, after I read little Schemer.
>>
>>58213450
New thread as it was supposed to be:

>>58214147
>>
>>58212362
{-# LANGUAGE TransformListComp #-}

import GHC.Exts

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

foo f = [ (the x, s) | (s,x) <- f, then group by x using groupWith ]

main = print (foo f)


λ runhaskell foo.hs
[('R',["a.txt","c.txt"]),('S',["b.py"])]
>>
>>58212737
>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
>>
>>58214245
http://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.
>>
File: 1411515525663.jpg (165KB, 1024x768px) Image search: [Google]
1411515525663.jpg
165KB, 1024x768px
>>58214186
I fucked up three threads, hope this is OK.

>>58214523
>>58214523
>>58214523
>>
>>58214557
You need to put this link in the OP:
http://www.ccs.neu.edu/home/matthias/HtDP2e/
>>
>>58214590
OK.
This thread will be last.

>>58214672
>>58214672
>>58214672
>>
>>58214689
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.
>>
>>58212362
>>58214201

Haskell btfo yet again
>>
>>58214201
λ 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"])]
>>
>>58215037
That ain't a dict, it ain't in the right order, and it ain't as simple.
>>
>>58215551
?
>>
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.
>>
File: functional.png (71KB, 1684x897px) Image search: [Google]
functional.png
71KB, 1684x897px
https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Functional_languages

>Functional languages include:
>C++
>C#
>Java
>JavaScript
>Python
>Ruby
>>
>>58218261
>xD it has lambdas so it's functional!!!
>>
File: lisp-programmers.jpg (155KB, 800x864px) Image search: [Google]
lisp-programmers.jpg
155KB, 800x864px
>>58218131

>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
>>
>>58218131
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.
>>
>>58219547
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?
>>
>>58219739

(map (l (x) (case (even x) "buzz") (odd x) "fizz")) list-of-nums)
>>
File: 1463609699864.gif (1MB, 500x500px) Image search: [Google]
1463609699864.gif
1MB, 500x500px
>>58219795
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?
>>
>>58219868
>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.
>>
>>58220006
>what is functional.h
>>
>>58219868
Try ocaml if you want to ease into functional, it has pretty good interop with c.
>>
File: Capture+_2016-12-27-22-38-30.png (489KB, 1396x671px) Image search: [Google]
Capture+_2016-12-27-22-38-30.png
489KB, 1396x671px
>>58213402
then you can have fun without any nerd
>>58219068
most lisp code is pretty imperative. CL doesn't have first class functions
>>58219627
, is making it think the RHS includes the pipe (so like f x, y |> z is f (x, y |> z)
>>58220153
also this
>>
>>58219739
https://github.com/haasn/fizzbuzz/blob/master/pattern-matching.hs
https://github.com/haasn/fizzbuzz/blob/master/cycle.hs
https://github.com/haasn/fizzbuzz/blob/master/monad-comprehensions.hs
https://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
>>
>>58219795
1. that's absolutely garbage code
2. that's not even a fizzbuzz
>>
>>58220341
>, 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.
>>
>>58220747
Make a Haskell web scraper
>>
>>58220892
I've done that before, I want to explore these languages. That is a good Haskell project though.
>>
>>58222881
There is normal /fpt/, nigger
Let this thread die
>>
>>58223231
This IS /fpt/ you thread splitting fuck
>>
>>58223247
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?
>>
>>58223301
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
>>
>>58223315
>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.
>>
>>58223466
>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.
>>
>>58223520
>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.
>>
File: 1477257788471.jpg (38KB, 362x346px) Image search: [Google]
1477257788471.jpg
38KB, 362x346px
>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?
>>
>>58223595
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
>>
File: 1466658110680.png (281KB, 1920x1080px) Image search: [Google]
1466658110680.png
281KB, 1920x1080px
>>58223609
>Are you sure it's linked properly?
Well, I must be doing something wrong. Maybe I am just retarded.
>>
>>58223671
i don't envy people having to link libraries, it's a fucking pain
are you following a set of instructions?
>>
>>58223595
Move to Linux instead
>>
>>58223726
Yes! I read several tutorials listed here: https://wiki.libsdl.org/Tutorials. I always think that I have done it correctly, but it seems I always get this error in eclipse.
Oh, well! It works in Code Blocks, so I might as well use that.
>>
Has programming gone too far?
https://gist.github.com/david-christiansen/3660d5d45e9287c25a5e
>>
Real World haskell is outdated trash, it talks about Haskell 98. Any other book that skips all the basic mumbo jumbo?
>>
>>58223942
Most of the extensions to Haskell 98 are semi-advanced, Real World Haskell came out in 2008

There's LYAH and the wikibook and also Haskell From First Principles, the latter is the most recent.
>>
>>58220747
Still looking for fun projects.
>>
>>58224009
Write a simple language and interpreter
>>
>>58224009
>>58224052
preferably a typed FP language
>>
Is common lisp dead?
Will investing months into common lisp as a second time programmer be a mistake?
>>
>>58225185
> Is common lisp dead?
Yes, more or less. The only alive lisps right now are clojure and elisp.
> Will investing months into common lisp as a second time programmer be a mistake?
Definitely will, unless you'll manage to find some job fixing 30 years old legacy code.
>>
>>58225229
Fuck me then, I already bought 5 books.
At least it will teach me lisp principles, right?
>>
>>58225245
Well yeah, also some universal programming principles, since many of the modern languages borrowed heavily from CL. So learning CL might be a good exercise.

Still, you should be careful no to turn into a CL-fanboy: most of CL literature is written in such an arrogant and opinionated way that many unstable minds become indoctrinated for life, believing that CL is the apex of PL development. RMS is a good example of how out-of-touch these guys are.
>>
what language should I learn to practice functional concepts
>>
>>58225781
Haskell, easily.
>>
>>58225794
I tried it a while back and the io is simply retarded, which makes practice pretty hard
>>
>>58225781
bw, is that you?
>>
>>58225816
IO in haskell is great, if you're a beginner just remember to use do-blocks, and use <- when you want to get an a out of an IO a
>>
>>58225816
main = do
putStr "What's your name? "
name <- readLn
putStrLn $ "Hello, " ++ name
>>
>>58221000
Ah fair enough. My point was just that learning Haskell will transfer to f# and Scala trivially :p
>>
>>58225816
The I/O isn't retarded, you just aren't used to it.

You could use the exact same logic for any other language concept from any language you're used to.
>>
>>58225185
>Will investing months into common lisp as a second time programmer be a mistake?
No amount of time spent practicing any language is a mistake.

Programming experience in any language makes you a better programmer for it. Also, programming isn't about learning some trade or skill - it's about having fun. As long as you're enjoying common lisp, there's absolutely nothing wrong about it.
>>
>>58223942
>>58223954
My issue with RWH is not just that it's outdated trash, but that it uses absolutely horrible style throughout.

Everything is always such a clusterfuck of ugly code and boilerplate, when there are almost universally way more elegant ways to achieve everything they do.
>>
>>58225816
this, they say that IO is contained, but its in fact the reverse, it creeps into the pure code.
>>
>>58226989
I'm guessing you don't really understand what ‘contained’ means in this context.

I/O creeping into pure code would mean pure code starts gaining side effects, but that simply isn't the case. It's contained because there are no side effects outside of the execution of IO, and this is what makes it such a powerful abstraction.

>it creeps into the pure code
It doesn't have to, if you want to write an I/O-free program, you can.
>>
{-# LANGUAGE TemplateHaskell #-}
>>
>>58227037
obviously, I mean in the sense that once IO is required for its results, then one needs to make many functions that will have to unwrap, rewrap, etc, because it has to be in the IO monad for the type system to accept.
>>
>>58227138
>unwrap rewrap

>>
<$>
>>=
>=>
.

what else do you need?
>>
>>58227162
do
a <- comp
return (somefunc a)

^ is why I hate
>>
>>58227138
1. You can build more powerful abstractions on top of IO, like pipes
2. You don't need I/O for the majority of your code
>>
>>58227188
somefunc <$> comp
>>
>>58227188
somefunc <$> comp


Like a baws.
>>
>>58227210
>>58227215
Goddamnit.
>>
File: 1470671602288.gif (607KB, 250x249px) Image search: [Google]
1470671602288.gif
607KB, 250x249px
>tfw was about to post somefunc <$> comp with all the other cool-kids but have a 40 second post cooldown
>>
Which FP paradigm isn't a meme?
>>
>>58227234
:^)
>>
>>58227284
pure, strongly typed, non-LISP
>>
>>58227363
(emphasis on non-LISP)
>>
New /dpt/, not going very well
>>58228476
>>
>>58230633
You better only be doing this when we get near the bottom of the board.
>>
>>58230769
pretty much
>>
>>58218935
Yes
What's wrong with that?
>>
>>58232033
Python's lambdas aren't real closures, so Python isn't an FP language
>>
What are
Prelude>

strings in Haskell code?
>>
>>58232084
What do you mean?
The thing in the REPL?
It tells you the modules that are included
>>
>>58232052
What makes them "not real" then?

Also
>closures

def generator(from, to):
def g():
i = from
while i < to:
yield i
i += 1
return g
>>
>>58232052
How are they not closures?
>>
>>58232117
>>58232127
They behave weirdly
>>
>>58232147
And that makes Python non-functional?
>>
>>58232147
Define weirdly
>>
>>58232161
Yes, they aren't real functions
>>58232173
I can't remember, here's a vaguely related stackoverflow question
http://stackoverflow.com/questions/4020419/why-arent-python-nested-functions-called-closures
>>
>>58232268
>Yes, they aren't real functions
They are

>I can't remember,
Lol
>>
>>58232309
He probably means 'they're not properly scoped'.
>>
>>58232431
>not properly scoped
This is meaningless. Python is function scoped, not block scoped.
>>
>>58232431
How that is a problem?
>>
>>58232521
>>58232489
It doesn't behave as Haskell, ergo it isn't functional. Good God, why are Python fags so autistic?
>>
>>58232540
Who's here autistic?
Haskellfagging is the autism.
>>
>>58232579
>Who's here autistic?
Clearly you. Stop sperging out and accept that Python is an imperative language, and not pure like Haskell. kek
>>
>>58232489
Function scoped... except for lambdas?

>>58232521
I didn't say it was a problem. I just implied it was dumb.
>>
>>58232579
He isn't an actual Haskell fag, he's clearly just false flagging.
>>
>>58232609
Please explain how lambda scope are somehow different, because I'm not following at all.
>>
>>58232609
OK, what's clever instead?
>>
>>58232649
The way it's done in Haskell.
>>
>>58232662
What's so different between Haskell and Python?
>>
>>58232671
Ignore that guy, he's false flagging.
He's probably not the guy you replied to.
>>
>An Introduction to Functional Programming Through Lambda Calculus
Will this also give me a better understanding of Calc?
>>
>>58232649
You, silly. You're far too clever to use Python instead of /fpt/-approved languages.

Also I just read up the thread to see how we got here, and this list is one of the dumbest I've ever read.
">xD it has lambdas so it's functional!!!" is truly a valid criticism: it genuinely is possible that this is actually how the article was produced.
>>
>>58232671
Haskell is pure, it's practically impossible to write code that has side-effects in it.

Python attempts to combine an imperative mindset with a functional mindset, and ends up doing both mediocre instead of one of them really good.

In Python you have the downsides of a FP language (GC'd, GIL) without the benefits (immutability) and you also miss out on the benefits of imperative programming (speed).

>>58232677
Fuck you asshole
>>
>>58232709
Haskell is a pure FP language.
Do you know what "pure FP" implies?
It implies the existence of impure FP.
>>
>>58232691
Just FYI, by 'list', I'm referring to the Wikipedia article in >>58218261
https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Functional_languages

It really is just a list of languages with lambdas (or, in the case of Python, something called 'lambda' that isn't a lambda).
>>
>>58232732
>what are side-effects
You're retarded or pretending to be retarded.
>>
An entire general? dedicated to functional programming?
Jesus christ, how horrible.
Also stop leaking into the real programming thread, you've got your own general now so fuck off from the dpt and stay in here forever please.

I'm leaving, I think I'm going to become sick if I stay here any longer.
>>
>>58232757
I know what side effects are.
Haskell is not the only FP language.
>>
>>58232808
just ignore the false flagging shitter

why even bother discussing haskell vs python in a thread about functional programming

go to the dpt if you want shitty language wars, this is off topic here
>>
>>58232808
I didn't say so fucktard. I said that Python is not a real FP language and that Haskell is a good example of one that is.

In what world is that the same as saying that Haskell is the only FP language? You are grasping for straws now.
>>
>>58232816
Fuck off, conspiracy tard. Not everyone that has a different opinion than you is a false flagging shitter. Do us all a favour and stay away from the /fpt/, we created this thread to have discussions without people like you interfering.
>>
>>58232844
If you seriously think
>>58232662
>>58232540
isn't false flagging, then you're the conspiritard
>>
>>58232084
pro-tip: you can change it in your ghci.conf
I changed mine to a lambda to make me feel like a leet hacker (but mostly to save horizontal space when I have multiple packages imported)
>>
>>58232860
you can also do it in the repl

:set prompt "string"
use %s for the modules
>>
>>58232844
>favour
You meant "favor"
>>
>>58232958
Literal shitpost

>>58232859
>>58232816
These too

Take it to /b/ guys.
>>
>>58232790
Have a (You).
>>
>>58233031
THERE ARE NO MORE '(You)'S
>>
>>58232709
>and you also miss out on the benefits of imperative programming (speed).
But are functional languages fast as they are?
One gigabyte garbage heap seems too huge.
>>
>>58212243
>core dumped!
>sys.exit()
lol
>>
>>58233083
That's just memory allocated and freed in Haskell
Haskell is pure, so it does a lot more allocation and de-allocation
>>
>>58233076
Have (You) too.
>>
>>58233083
Nice meme.
>>
>>58233137
That's not a meme.
http://stackoverflow.com/questions/6623391/how-to-gain-control-of-a-5gb-heap-in-haskell
>>
>>58233095
Haskell is GC's because it's high-level, not really because it's pure.

Any sufficiently high-level TC language has GC these days, because static resource allocation for a high-level turing complete language is an unsolved (and probably unsolvable) problem.

Anyway, the solution to garbage collection is to keep your working set small and do the allocation of large resources manually (e.g. using an abstraction like pipes-safe)
>>
>>58233188
Purity leads to more GC because of immutability
>>
>>58233172
It is a meme, it's been posted in the last three /dpt/ we had today alone.

You can write retarded Python code that eats away memory too. Or Java code.

It's a property of having immutability and lazy evaluation. However, Haskell's GC is fast as hell, and doesn't have to do BFS like other (slow) GCs for example.
>>
>>58233204
This makes no sense. What does “more GC” mean? You either have GC, or you don't
>>
>>58233251
More garbage means more garbage collection
>>
>>58233273
That's simply not true
>>
>no Javasript in OP
But it's functional
>>
>>58233463
no it isn't
>>
>>58233546
but it is
>>
>>58233546
How so?

>inb4 it isn't haskell
>>
>>58233546
>>58233569
If it wasn't, we didn't have such a language as Elm.
>Elm is a functional language that compiles to JavaScript
And Elm is listed in OP.
Therefore it's functional.
>>
>>58233740
>Haskell compiles to asm
>asm is functional
>>
>>58233740
>haskell compiles to C
>C is functional
>>
>>58233804
But you can make C functional with function pointers
>>
So, exactly how purity influences on safety and computation speed?
What is purity useful for?
>>
>>58234245
help
>>
>>58234245
Purity allows for far more aggressive optimizations, like liberal term rewriting / inlining and cheap parallelization (due to no side effects, it doesn't matter what order to evaluate things in, and therefore it can be easily parallelized)

In general, purity helps a lot when it comes to compiler optimizations and general ability to write efficient programs. It also allows you to build more powerful abstractions, which can help transform your programs in ways to make them more efficient (e.g. automatically reassociating tree computations for maximum pipelining)

Purity also helps you write safe code, because code without side effects is code that can be reasoned with in isolation from the execution environment. Since functions only depend on their inputs, you can statically prove certain safety properties, or even enforce them using the type system. It also makes unit testing easier and more powerful (e.g. automatically generating unit tests)
>>
>>58235046
>liberal term rewriting
like replacing “man page” by “person page”?
>>
>>58235104
that's short for manual you utter dipshit
>>
Is Rust a functional language?

Which should I learn next, Rust, Idris, or Elm?
>>
>>58235370
Stop mansplaining and write an HTML tutorial you sexist.
>>
>>58235381
Rust is functional in a lot of ways but not so much in others. It has a pretty precise type system when it comes to resource management and effects. However, its support for higher order programming is kind of poor. It doesn't even have types of higher kind or rank.
>>
>>58235438
>It doesn't even have types of higher kind or rank
Isn't that true of OCaml and F# too?
>>
>>58235481
I'm not sure, but I have found it to be somewhat limiting in practice regardless, particularly when it comes to associated types in a trait.
>>
>>58235481
>>58235495
Definately true of f#; not an ML'er though so dunno but glogl sais https://github.com/ocamllabs/higher
>>
>>58235520
It's a strange omission given that the language is otherwise pretty type-savvy and that even C++ has higher kinded types (template templates).
>>
>>58235548
wrt f#, HKP would require that parameterized types be erased for the CLR, breaking compatibility with C#, or else extending the CLR to support it (not likely). plz send teh codes here: https://github.com/dotnet/coreclr/issues/6524

From the OCaml paper, the main obstruction seems to be related to the general lack of type injectivity.

HKP in C++ is pretty ad-hoc and much more limited than in Haskell. I don't think you can have anything like `Fix` in C++; the template instantiation would diverge.
>>
>>58236129
You couldn't "really" have Fix, but you could instantiate with void*
>>
>>58212362
void foo() { std::cout << "{'S': ['b.py'], 'R': ['c.txt', 'a.txt']}"; }
>>
What exactly is the difference between Functional programing and OOP programming apart from everything in OOP being associated to types and classes which build on inheritance? It feels like Functional programming is a subset of OOP in a sense. Any real answers?
>>
>>58237965
The key aspect of FP is higher order functions
FP also normally features strong type systems
>>
>>58237965
Fundamentally, it's the thought process. OOP is designing software by modelling it as systems of objects that send messages to each other. FP is designing software by modelling it as functions that transform data. Thus, first class functions and higher order functions are important to FP because they allow a high degree of code reuse.
>>
>>58237988
And by 'high order functions' do you mean everything is just done by functions which serve their own purpose? Kinda vague I need you to explain

>>58237995
So youre trying to allude that speed is a pro when it comes to functional programming as opposed to being slow OOP?

Is there anything OOP can do that functional cant? I can't imagine why, but Idk
>>
File: 1478304766015.jpg (17KB, 400x327px) Image search: [Google]
1478304766015.jpg
17KB, 400x327px
>gay shit in op
>>
>>58237965
OOP is a highly stateful paradigm in which objects interact by forming networks of instances that evolve state by exchanging messages.

FP is a highly stateless paradigm, in that functions behavior depends only on their inputs and doesn't change over time.

They're very different. But to answer the question of which is a subset of the other - the answer is that they're equivalent. You can embed functional programming into OOP languages, and you can embed OOP programming into functional languages.
>>
>>58238028
>OOP programming
>object-oriented programming programming
>>
>>58238026
>And by 'high order functions' do you mean everything is just done by functions which serve their own purpose? Kinda vague I need you to explain

Higher order functions are functions that take functions as parameters, for example C#'s LINQ, C++'s <algorithm>, some of Java 8's new features, thinks like promises, async, etc.
>>
>>58238026
>So youre trying to allude that speed is a pro when it comes to functional programming as opposed to being slow OOP?
I wasn't going for that, but it is pretty much the case. FP is an advancement/refinement of procedural programming, which is how a CPU operates. OOP is a complete departure from it.
>>
>>58238028
>You can embed functional programming into OOP languages, and you can embed OOP programming into functional languages.
How is this true? If I want to make an inheritance of an Animal class which evolves into more specific classes, I don't think you can do this in C, can you?

>>58238050
Can you give me a very simple example? I mean I don't get why thats a key aspect, if function A is an input of function B function A just evaluates to something with a strong type (int, bool, char, etc..) so I don't understand how thats a key aspect when literally everything does this

>>58238058
If you dont mind as well could you come up with an example to demonstrate the difference (Idk some hello world program) between FP and OOP?

Id send an email to my lecturers but the semester hasnt started yet lol
>>
File: a higher order function.png (3KB, 278x87px) Image search: [Google]
a higher order function.png
3KB, 278x87px
>>58238081
>Can you give me a very simple example? I mean I don't get why thats a key aspect, if function A is an input of function B function A just evaluates to something with a strong type (int, bool, char, etc..) so I don't understand how thats a key aspect when literally everything does this
>>
>>58238081
>How is this true? If I want to make an inheritance of an Animal class which evolves into more specific classes, I don't think you can do this in C, can you?
C isn't a functional language. But of course you can do that, C is Turing-complete and there has to be some way that the higher-level OOP languages compile inheritance.
>>
>>58238081
>How is this true? If I want to make an inheritance of an Animal class which evolves into more specific classes, I don't think you can do this in C, can you?
The trivial way to do it is with explicit subtyping; i.e. having an explicit function to convert a Horse to an Animal. Sure, it's not as effortless and automatic/implicit as in an OOP language, but the same is true for any language embedding
>>
>>58238110
>C isn't functional language
Really? What is C then

>>58238104
Oh I see, but its strange, C# can do a similar thing (Delegates right? system event handling?) so what is C#, OOP or FP? bit confuse..

>>58238113
I see
>>
>>58238113 (cont)
For example, you could have the subtyping built into the struct itself

struct animal {
// vars
int x, y;
const char *name;

// dynamic methods
void (*makeSound)(struct animal *this);
}

struct horse {
// subtype
struct animal parent;

// own vars
struct color maneColor;
}

const struct horse horsePrototype = {
.parent = (struct animal) {
.name = "horse",
.makeSound = horseNeigh,
},

.maneColor = brown,
};

void makeSound(struct animal *this_) {
struct horse *this = (struct horse *) this_;

printf("%s goes NEIGH!\n", this->animal.name);
}
>>
>>58238176
>Really? What is C then
C is procedural with a very low degree of abstraction.

>C# can do a similar thing (Delegates right? system event handling?) so what is C#, OOP or FP? bit confuse..
C# is multi paradigm to an extent, but primarily OOP. It has decent support for higher order functions but terrible support for most other things functional.
>>
>>58238183
sorry that last function should be called horseNeigh

usage

void main() {
struct horse ed = horsePrototype;
ed.animal.name = "Ed";
ed.animal.makeSound(ed);
}
>>
Anyone who thinks python is a functional programming language can shut the fuck up and lick guido van rossum's asshole

>"C is a functional programming language"
every day we stray further from god's light
>>
>>58238183
Mane?
>>
>>58238176
C# has a lot of FP features
>>
>>58238183
I see makes sense, although not too well versed in C I do understand the point youre making, thanks
>>
>>58238284
C# is a functional language since 3.5
>>
How far through the wikibooks book on Haskell should I go before going off to just experiment and code things?
>>
>>58238906
>before going off to just experiment
You must experiment as ASAP
>>
>>58238925
>as as soon as possible
>>
>>58239023
Is there a problem anon? Youi do not like what you see?
>>
>>58238235
It has functions, therefore it's functional.
>>
>>58239527
No, it must have closures to be functional.
>>
How's Let Over Lambda? Is it a useful book?
>>
>>58239745
I can make function to return the function pointer of the inside function.
How is it not closure?
>>
>>58239772
it claims to be the very best, I haven't read it yet though.
>>
>>58239848
You can't capture scope. Don't argue, you would be ridiculous.
>>
>>58239848
>closure
>isn't closing over anything
>>
File: 1482946611482.jpg (234KB, 1136x1000px) Image search: [Google]
1482946611482.jpg
234KB, 1136x1000px
>No ML in OP
Pourquoi ?
>>
>>58240242
OCaml and Haskell
>>
File: rainbow-parens.png (32KB, 486x252px) Image search: [Google]
rainbow-parens.png
32KB, 486x252px
>>58212144
Use proper indentation and the parens fade away. Paredit and rainbow parentheses help quite a lot too.
>>
>>58240212
>>58240203
GCC supports nesting, so it will take the scope.
Also, C++ has lambdas.
>>
>>58212017
Maybe add Paul Graham's ANSI Common Lisp and On Lisp books to OP?
>>
>>58240400
>for
un-lisp-like syntax
>>
>>58240450
>he didn't see the true light of LOOP macro
>>
>>58240465
>the average Lisp "("("programmer")")"))))) spends more time writing macros to make his code less like Lisp than he does writing code
>>
>>58233866
Function pointers doesn't turn functions into first class citizens. Function pointers are only a function reference, true functional programming languages allow treating functions as data, implicitly this means that functions can be built and generated and then later executed.

C++ allows this, both old-style functors and modern C++11 lambdas are true first class citizens. Lambdas capture state, functors have their own state (and you can pass state to them). Purists will probably argue that functors aren't true, because you need to explicitly pass state to them.
>>
>>58240429
>GCC supports nesting, so it will take the scope.
It doesn't take the scope and you're relying on undefined behaviour that's going to make you have a bad day and get garbage data.

>Also, C++ has lambdas.
Yes, C++ is functional. C is not. See >>58240527
>>
>>58240465
>>58240450
loop and format are, admitably, the least-lispy parts of Common Lisp, but that wasn't the point
>>
Do you prefer effect systems or monads for state?
To the people using Haskell on a daily basis: Doesn't the bad composability of monads ever annoy you?
>>
>>58240701
>bad composability
this isn't true, in fact the opposite
>>
I think Rust's users broke
https://www.reddit.com/r/rust/
>>
>>58240748
I find monad transformers to be a pain in the ass.
>>
>>58240816
Their braincogs literally rusted
>>
>>58240848
Are you not using MTL?
>>
>>58240853
Not if I can help it.
>>
>>58240886
that's probably the problem then

you don't need to lift if you use the MTL
>>
should I use the loop or the iterate macro?
>>
File: 1474429344828.gif (146KB, 300x375px) Image search: [Google]
1474429344828.gif
146KB, 300x375px
>>58240433
Lisp is not even functional.
It must be purged from the thread for the sake of true functional languages.
>>
>>58239527
Functional programming relies on functions being first class citizens, which in turn implies the existence of closures.
>>
>>58240701
>Doesn't the bad composability of monads ever annoy you?
What do you mean by monad compositions? Are you talking about monad transformers? If so, the thing that annoys me the most is the way mpl handles its type class lifting. Blows up into O(n^2) complexity.

I believe a better system can be designed, which can lift arbitrary monad classes over arbitrary transformers, by using newer GHC extensions. But I haven't given it a try.
>>
>>58243857
No i think those are still independent. Closures tells you *what* your internal Hom should be (ie, a lambda abstraction); but higher order functions only requires *that* you have them. All terms of the SKI calculus are higher order functions, but it has no name capture because it has no capture at all.
>>
>>58243952
>it has no capture at all.
should be "no names at all" i fugged.
>>
>>58243952
>All terms of the SKI calculus are higher order functions, but it has no name capture because it has no capture at all.
Good point.

So do you think embedding SK into C makes C a functional programming language?
>>
>>58240701
I prefer substructural types.
>>
>>58244023
Interpreting SKI in another language only proves its "Turing compete", You would need to implement SKI combinators directly in the host language to say anything about it expressivity.

C doesn't have anything like parametric polymorphism, so you could write those combinators at each type you need to use them at (perhaps with judicious use of preprocessor macros) for a simply-typed version, or with judicious use of void* for untyped SKI.

I think C "has higher order functions" because of function pointers. I think there are a few additional features one should ask for before you try to call a language "functional" in the Scheme/ML sense.

Closures are one example of those features. The others are ADT's, and at least one of
parametric polymorphism and hygenic macros.

C has only HOF; C# has HOF and closures; C++17 has non-recursive parametric polymorphism, closures and HOF. None of those have ADT's, so they're quite a bit "less functional languages" than Scheme or ML
>>
>>58244216
C++17 adds std::variant<>
but it's literally trash

they could've added a pattern matching function, but no
they add some bullshit LITERALLY USELESS oop "visit" function
>>
So let me get this straight. The /dpt/ has reached the bumplimit after less than 7 hours.

The functional programming thread is still alive and well after 48 fucking hours.

WHY THE FUCK ARE YOU MAKING A NEW GENERAL WHEN THERE'S OBVIOUSLY JUST THREE DIFFERENT PEOPLE CONTRIBUTING IN THIS THREAD?

I'm reporting these generals as spam.
>>
>>58244235
You do realize sum types are just dual to product types? There's no reason to add pattern matching to a language if you can get away with simply passing in a tuple of case handling functions (visitor). Dependent types are one case where typically you can't get away with it because you want dependent pattern matching and whatnot.
>>
>>58244261
~290 posts
>71 posters
So, about 4 posts per person. I think that's not bad.
>>
>>58244288
>You do realize sum types are just dual to product types?
Sure, lots of languages work that way, but std::variant isn't a sum type. std::variant<int,int> can't tell the difference between the left and right cases.
>>
>>58244288
>There's no reason to add pattern matching to a language if you can get away with simply passing in a tuple of case handling functions (visitor).
That's not how it works. That's what I said it should be.

http://en.cppreference.com/w/cpp/utility/variant/visit


See the
 using T = std::remove_cv_t<std::remove_reference_t<decltype(arg)>>;
if constexpr (std::is_same_v<T, int>)

?
>>
>>58244306
std::variant is a sum type, it keeps an index
>>
>>58244307
Oh wow, that's terrible.
>>
>>58244216
>You would need to implement SKI combinators directly in the host language to say anything about it expressivity.
Hmm, I tried doing this but this is actually where I fall into the lack of closures again.

Something like
k (s k) k
being valid requires ‘s k’ to be a valid partially applied function, i.e. the ‘k’ argument needs to be enclosed into the function returned by ‘s’ as you pass it around, forming a closure.

So I still don't see how SK doesn't imply existence of closures as a requisite for FP.
>>
>>58244318
Ah i see. You are correct sir. >>58244235 is still right to be salty because there's not actually a way provided in the standard to eliminate a std::variant that makes use of that index. You can read the index, and you visit, but visit doesn't get the index.
>>
>>58244288
>There's no reason to add pattern matching to a language if you can get away with simply passing in a tuple of case handling functions (visitor).
How is that any different from pattern matching?
>>
>>58244385
In most cases it's not functionally different, I realize that's what he meant now. But you don't see many languages doing that over having full pattern matching syntax.
>>
>>58244385
Not him but I think it implies... prettier syntax?
>>
>>58244420
>>58244421
Sometimes people actually deliberately do this even in functional languages (CPS) because it allows for more efficient composition.

i.e. you can transform
data Either a b = Left a | Right b

foo :: (Show a, Show b) => Either a b -> String
foo (Left x) = show x
foo (Right x) = show x


into

type Either a b = forall r. (a -> r) -> (b -> r) -> r

left :: a -> Either a b
left a f _ = f a

right :: b -> Either a b
right b _ g = g b

foo :: (Show a, Show b) => Either a b -> String
foo e = e show show


And then compose a chain of pattern matches without ever having to construct or take apart a value. Since function calls are more efficient than heap allocations and stack crawling, a CPS'd chain of “pattern matches” is often beneficial for performance.

So I don't think it's too unreasonable for a language to consider being fundamentally based on this concept, especially because you get it for “free” just by having first-class closures.
>>
>>58244371
>>58244318
Hmm. still staring at it. No i am back to my original view that std::variant fails to be a sum; it's an untagged union. I see no way to construct a std::variant<int,int> that can distinguish between left and right cases. there's an index to get which case it gave you, but you can't request "the second one, not the first"
>>
>>58243857
>which in turn implies the existence of closures.
Not with dynamic typing.
>>
>>58244491
either
is a function in Prelude that pattern matches either
there's also "bool" in Data.Bool (horribly unintuitive argument order) and "maybe" in Data.Maybe

If you think about it, foldr pattern matches a list

>>58244523
std::get<number>
>>
>>58244533
How do you implement a ‘const’ function without closures?
>>
>>58244572
>If you think about it, foldr pattern matches a list
it's one way of pattern matching a list

It depends on whether you want to recursively replace all constructors or just replace the outermost construct. In other words, church vs scott encodings.

-- requires infinite types, or a sufficiently infinite embedding
type Scott a = forall r. r -> (a -> Scott a -> r) -> r

-- requires no infinite types
type Church a = forall r. r -> (a -> a -> r) -> r
>>
>>58244491
Yeah, that's what Church and Scott encodings get you. They're pretty good for keeping a language simple especially when it's more low-level (like in Rust where function types are traits to be implemented however you like instead of heap-allocating all closures with no programmer control).
>>
>>58244523
>std::get<number>
i can tell them apart, but how do i construct one in the first place. I need a variant<int.int>::put<number> to say which one i wanted to make.
>>
>>58244638
http://en.cppreference.com/w/cpp/utility/in_place
>>
>>58244615
>They're pretty good for keeping a language simple especially when it's more low-level
Heh, reminds me of the low-level intermediate language I used as starting point for compiling functional languages to .NET

https://github.com/haasn/compilers/blob/master/STG/examples/IO.stg
>>
>>58244523
std::variant is kind of bad by itself
so I just consider it a union storage type
that you can use to make a useful type like so
template <typename T> 
struct Left { ... };
template <typename T>
struct Right { ... };
template <typename A, typename B>
using Either = std::variant<Left<A>, Right<B>>;
>>
>>58244663
People don't believe me when I say C++ is irredeemable and can never be a good language
>>
>>58244680
C++ is hated by the majority on 4chan... meanwhile the industry widely uses it
>>
File: 1481256594498.gif (2MB, 279x350px) Image search: [Google]
1481256594498.gif
2MB, 279x350px
>>58244638
>>58244660
Oh my god i get it. okay, variant really is a sum; variant<int,int>(5) is apparently ill-formed; you discriminate with variant<int,int>(in_place_index_t(0), 5).
>>
Why Haskell is chosen over other FP languages?
What's so great with it?
>>
>>58244751
It's so pure you can't do anything meaningful with it. It's a perfect analogue to the NEETs who use it.
>>
New thread:

>>58244769
>>58244769
>>58244769
Thread posts: 306
Thread images: 18


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.