[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: 100
Thread images: 9

File: 1482055600767.png (818KB, 1280x719px) Image search: [Google]
1482055600767.png
818KB, 1280x719px
Next-level programming thread.
Last one: >>58268853

Resources:
>Erlang
http://learnyousomeerlang.com/content
>>Elixir
http://chimera.labs.oreilly.com/books/1234000001642/index.html
http://elixir-lang.org/learning.html
>F#
http://fsharp.org/learn
>Haskell
https://en.wikibooks.org/wiki/Haskell
https://0x0.st/pbp.pdf
>Lisps
>>Common Lisp
http://gigamonkeys.com/book
http://www.cs.cmu.edu/~dst/LispBook/book.pdf
Paul Graham's ANSI Common Lisp
On Lisp
Common Lisp Recipes
Land of Lisp
An Introduction to Functional Programming Through Lambda Calculus
>>Clojure
http://www.braveclojure.com/foreword/
The joy of Clojure
>>Scheme
SICP
Essentials of Programming Languages
How to Design Programs:
http://www.ccs.neu.edu/home/matthias/HtDP2e/
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/
http://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
https://guide.elm-lang.org/
>>PureScript
http://www.purescript.org/learn/

Feel free to add more.
>>
File: 148152969623.png (523KB, 722x525px) Image search: [Google]
148152969623.png
523KB, 722x525px
>>58301640
first for state is not evil
>>
>>58301718
Mutable state is :^)
>>
>>58301735
>>58301718

Mutable state isn't evil, but it's dangerous. It has it's uses, but abusing it all the time (like in imperatives and OOP) is source of many a problem.
>>
>>58301735
>:^)
>>
>>58301735
>immutable state
>>
Reminder that there are now two metaprogramming languages called rascal
>>
>>58301735

reminder that the space of all possible mutable states in a program forms a function chain :^)
>>
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.
>>
>>58303019
thanks for the bump pastafriend
>>
is lisp a functional programming language?
>>
>>58303701
no
>>
>>58301640

Guys, I have to make a decision which language to learn..
Right now I'm thinking about either Erlang/Elixir, Scala or.. *ehem* ..C++.

Some month ago I've dabbled in Erlang a little bit and found the syntax really neat (concise like C), I also think the actor model and underlying VM are great.

Recently I looked at Scala, and it is kinda nice:
They took Erlang's actor modell, gave Java a much cleaner Syntax and - last but not least - you can actually get a Job with Scala. I find Java annoying, but Scala makes it bearable. Of course you can find Jobs for stuff like Haskell, but it's not that many and I'm not that much of a hotshot that I can outperform the 100 other guys that are applying for a Haskell vacancy..


Downsides are that I found out you have to be careful with Scala. There's a lot of functionalities that actually make your program slower than the Java equivalent if you don't know _exactly_ what you are doing.


In other words:
I think Scala is somehow like C++: incredibly powerful, but not as easy as you think it is. Now if I have to put a lot of effort in learning Scala, I might as well get somehow decent in C++, with more job opportunities and about the same amount of "high level magic", if you go down into the details of the language. I'd also argue that C++ can be used as semi-functional language.


What do you think?
>>
>make a spinoff programming thread
>more anime girl OP pics

for shame
>>
>>58303916
>>more anime girl OP pics
Great, isn't it?

Much better than using some stupid XKCD comic
>>
>>58303019
>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.
Welcome to /g/
>>
>>58303701
They made us use Lisp for an AI course at uni and we were not allowed to use looping constructs because we were supposed to learn functional programming.
As soon as I wanted to do anything nontrivial, I always got stack overflows because Lisp does not do tail call optimization.
I'm fine with learning FP, but then also give us an FP language ffs…
>>
>>58304184
>Lisp does not do tail call optimization
let me guess. You never bothered to compile your code
>>
>>58301640
What about DrRacket?
https://racket-lang.org/
>>
>>58304784
I ended up doing it, but it's bullshit having to rely on implementation features that the language standard does not guarantee.
>>
>>58304808
I'll be adding this
>>
>>58304992
It's only "Racket" btw. I missed
>>
>>58305139
Isn't Racket a dialect of Scheme?
>>
>>58305171
Yes.
But having a list of useful schemes might be pretty nice. I mean, the books are lovely, but suggesting implementations as well would be great.

I'd suggest GNU Guile should be added to that list. Comes with tons of libraries, can call C code easily, well supported, works with Geiser (SLIME but for Scheme), and has lots of documentation.

Actually, implementations of Lisp:
> - Common Lisps -
LispWorks
SBCL
CLISP

> - Schemes <
Chicken Scheme
GUILE
Racket
>>
>>58305299
>no Chez scheme
Enjoy your slow shit
>>
>>58305299
>But having a list of useful schemes might be pretty nice. I mean, the books are lovely, but suggesting implementations as well would be great.
I think I just must create /fpt/ webpage somewhere or open the page on installgentoo wiki.
>>
I've been trying to get a Haskell build environment set up on my RPI but it's taking ages. Stack has 4 dependencies with bugs that wont build.
>>
>>58307685
Package dependencies are a bitch, what packages?
>>
>>58307685
>>58307748
Or do you mean stack itself?
if so i'd recommend haskell platform
>>
>>58307685
I fear your machine is weak for Haskell.
>>
>>58307685
vector-algorithms-0.7.0.1 and unicode-transforms-0.2.0 fail with LLVM opt errors.

>>58307757
Haskell platform is outdated in Ubuntu repos

>>58307777
I've managed to make it this far..
>>
>>58307788
install gentoo on it
>>
>>58307831
I'm not that suicidal
>>
>>58307978
Why do you think it's "suicidal"?
>>
>>58305299
R A C K E T I S N T S C H E M E
A
C
K
E
T

I
S
N
T

S
C
H
E
M
E
>>
ocamlc -annot -safe-string -strict-sequence -w A -warn-error A
>>
>>58308106
wew
>>
https://youtube.com/watch?v=5lL1xYHDCSk

Clojure fighting the good fight.
>>
>>58308904
Fighting against decent programming
>>
File: 1478415807930.jpg (67KB, 800x557px) Image search: [Google]
1478415807930.jpg
67KB, 800x557px
>reading about Church numerals on Wikipedia
>mfw Haskell code is more understandable to me than lambda notation
me feels real dumb
>>
why isn't Practical Common Lisp in the OP?
>>
>>58307685
Are you compiling in the RPI? I remember that I use a qemu VM to compile Haskell binaries for the RPI.
>>
>>58303900
>I might as well get somehow decent in C++, with more job opportunities and about the same amount of "high level magic"
I've never programmed C++ professionally, but I suspect the amount of (quasi-)functional C++ jobs are even smaller than the amount of Scala jobs. And if you're not doing serious high-performance stuff then expect the same OOP "best practices" that you get to enjoy with Java.

If you need high performance then you should probably avoid mainstream functional programming languages in general. They're good at solving problems elegantly, but getting high performance out of them often involves ugly, complicated, unsafe code that's basically imperative anyway. Or write the critical sections in C and use FFI.

I'm learning Scala because I want to accumulate professional experience in a functional programming language. Scala is pretty ugly imo and I would suggest at least dabbling in Haskell or whatever so you can remind yourself what decent language looks like.
>>
>>58311666
Yes a RPI 2. The problem is with some cabal packages that fail to build. One is a known bug on arm and the others have llvm optimization errors.
>>
will we ever be able to use quicklisp without getting MITM'd?
>>
>>58301762
Aren't OOP and FP both essentially ways of addressing the "global variable" problem?
>>
>>58303701
It's multi-paradigm, but capable of functional programming, and is commonly associated with FP.

>>58304828
Pretty sure the C standard doesn't require TCO, but any modern compiler used to build PC applications has it, so if your program already assumes a PC environment, there's really no harm in assuming TCO. I would assume the same is true of Lisp; don't get too caught up in being strictly-conforming if the nature of the program limits it to certain environments in the first place.
>>
File: forth_on_the_atari.jpg (62KB, 450x722px) Image search: [Google]
forth_on_the_atari.jpg
62KB, 450x722px
>>
>>58309435
Don't be, that's normal.

Esoteric notation like for LC and other theoretical languages are always horribly hard to read. I also find stuff like scheme stupidly difficult to parse compared to the equivalent Haskell examples.

Language simplicity is anti-proportional to program simplicity, and LC/Scheme/etc are all designed to maximize language simplicity so they can be used for formal proofs etc.
>>
File: 1477319531144.jpg (13KB, 142x250px) Image search: [Google]
1477319531144.jpg
13KB, 142x250px
every language is technically a functional language if you just ignore the non-functional parts
>>
>>58313958
This is like how people reduce "object-oriented" to apply to any case where a traditional object, something like a traditional object, or anything called an "object" regardless of whether it has anything to do with encapsulation and message passing is used.

If a language is functional it means it explicitly supports functional programming features and makes it easy to use them often.
>>
>>58311717

Thanks!

So I should learn Haskell (for exercise and amusement) and Scala (for getting a job with a functional language)?

Can someone comment on wether Haskell is harder than Erlang? How much time did you need to be "intermediate" in Haskell?
>>
>>58311260
http://gigamonkeys.com/book
>>
>>58315571
If you learn Haskell then you'll know how to write functional Scala. Regular Scala is just OOP+Java bullshit on top of that
>>
>>58313632
>I also find stuff like scheme stupidly difficult to parse compared to the equivalent Haskell examples.
I dunno, for me Scheme is pretty easy and understandable.
>>
File: 1445695675422.jpg (25KB, 321x322px) Image search: [Google]
1445695675422.jpg
25KB, 321x322px
data Nat : Type where
zero : Nat
succ : Nat => Nat

_+_ : Nat => Nat => Nat
m + zero = m
m + succ n = succ (m + n)

// can range over more than just types
class Monoid (A : Type) (a : A) (f : A => A => A) where
left_id : (x : A) => (f a x == x)
right_id : (x : A) => (f x a == x)
assoc : (x y z : A) => (f (f x y) z == f x (f y z))

instance Monoid Nat _+_ zero where
// prove as usual

// monoid inferred
foo : (x : A) => (x + succ zero == succ x)
foo x = cong succ (right_id x)
>>
>>58316373
What did you mean by this?
>>
>>58316409
Something about the succ
>>
>>58315685
Here's an example where I gave up trying to parse the scheme code (reproduced almost verbatim)

C[shift f E] = (lambda (c) (let ((f (lambda (x) (lambda (c2) (c2 (c x))))))
(C[E] (lambda (v) v))))


compare to a literal Haskell transliteration
C[shift f E] = \c -> let f x k = k (c x) in C[E] id
>>
>>58316373
Why is it x : A and not
x : Nat
in your foo?
>>
>>58315422
C# is functional?
>>
>>58317717
Yes.
LINQ, async, are related to monads
SQL is mostly pure
>>
Are Erlang ports just an interface to play around with "other language"-libraries?
>>
>>58317786
But SQL isn't a part of C#
>>
>>58320323
But you can see the relationship
>>
>>58320406
C# has nothing to do with SQL in this context.

LINQ has nothing to do with SQL.

LINQ-to-SQL is only a small component of LINQ, and the fact that 'query' is one part of the acronym doesn't mean what you think it means.

That being said, LINQ (particularly the method-syntax) is certainly functional in nature, with things like
.SelectMany()
already being most of a monad as-is.
>>
>>58320593
I thought LINQ had some SQL integration?
and SQL is a mostly pure, functional language
>>
>>58320626
declarative =/= pure, functional
SQL isn't even Turing complete
>>
File: 1483369485134.gif (995KB, 280x201px) Image search: [Google]
1483369485134.gif
995KB, 280x201px
>>58320935
>SQL isn't pure or functional
>>
File: anal beads.png (26KB, 711x435px) Image search: [Google]
anal beads.png
26KB, 711x435px
>>58320626
In what capacity do you mean by "some SQL integration"?

LINQ is many things, and one component of LINQ that is rarely used anymore is called LINQ-to-SQL, and this is simply a way for you to use LINQ (method or query syntax) to interact with a database. For example, you can load an MDF file and apply LINQ-based queries to interact with the DB.

LINQ itself is commonly used as set comprehension for objects in the program. Let's say you have a list of a particular object, and that object has many properties. You can do set comprehension on this list of objects using various LINQ methods that are counterparts to many functional language features you already know and love.

Here's where the confusion happens: because LINQ has a "query syntax" that looks like SQL, people tend to attribute it to being "just a SQL thing", whereas this isn't the case at all.

The following two methods do roughly the same thing:
var query =
from thing in things
group thing by thing.Lmao into g
select new { LmaoGroupName = g.Key, AverageFlaccidBenisSize = g.Average(x => x.LengthOfBenis / 3.0)};

var query2 =
things.GroupBy(g => g.Lmao)
.Select(g => new { LmaoGroupName = g.Key, AverageFlaccidBenisSize = g.Average(x => x.LengthOfBenis / 3.0) });


Obviously, the former looks very SQL-like, but in and of itself doesn't apply to SQL or relational database in any way other than aesthetics and similar functionality.

Now, you may know all this, but I was hoping this would clear up some confusion for some anons.
>>
>>58320968
If you want to claim something is functional, you'll need to at the very least show me how to define the ‘s’ and ‘k’ combinators in it.
>>
>>58321207
No, you don't.
And functional languages don't need to be turing complete, either.
>>
>>58321255
IF you can define functions and pass around functions, you can define ‘s’ and ‘k’

If you can't define ‘s’ and ‘k’, you can't define functions. If you can't define functions, it isn't functional

QED

stop fucking calling everything that's declarative “functional“, it's getting tired
>>
>>58321255
>And functional languages don't need to be turing complete, either.
being able to define ‘s’ and ‘k’ does not imply turing completeness, either
>>
File: bingoboiz.png (13KB, 677x341px) Image search: [Google]
bingoboiz.png
13KB, 677x341px
I'm doing C and trying to create a bingo game. for the bingo game a "caller" will call out random numbers every time the user enters 1. (I know the output on my bingo cards is wrong but its just for a test) I'm trying to save all the caller numbers into an array and then display them once the user enters 2, but for some reason it only saves the LAST number the caller has called and displays that instead of displaying ALL the numbers he has called, does anyone know why this is?
>>
>>58321605
I'd have to see the code
>>
>>58321648
My code is disgusting pleb tier beginner garbage, are you sure you wanna see it?
>>
>>58321605
>>58321664
What the fuck does this have to do with functional programming?

Go back to >>>/g/dpt plebeian.
>>
>>58321664
code or gtfo
>>
>>58321648
please be gentoo with me.

switch (choice2)
{
case 1:
callerNumber = rand() % 91 + 1;

printf("The Caller Picks A Number, The Number %d Was Drawn\n", callerNumber);

printf(" \n");

for (int i = 0; i < 10; i++) {

stats[i] = callerNumber;
}

break;
case 2:
printf("This Is Where The Stats Should Be Displayed\n");
printf(" \n");
printf("Here Is Player 1's Bingo Card\n");
printf(" \n");


for (row = 0; row<5; row++)
{
for (col = 0; col<5; col++)
{
printf("%d\t", bingo[row][col]);
}
printf("\n");
}
printf("Here Is All Of The Callers Numbers\n");
printf(" \n");

for (int i = 0; i < 10; i++) {
printf("%d ", stats[i]);
}

break;
case 3: printf("Quitting program!\n");
exit(0);
break;
default: printf("Invalid choice!\n");
break;
}

}
>>
>>58321717
>for (int i = 0; i < 10; i++) {
>
> stats[i] = callerNumber;
> }
You set every element in the stats array to the same value, "callerNumber"
Is this intentional?
>>
>>58321733
I thought thats what needed to be done if I wanted each caller number to be put into the array?
>>
>>58321756
>each caller number
There's only one caller number.
You assign a random number to it, once.
There is one number.

Then you fill the entire array with that one random number.

Do you want the entire array to be random?
>>
>>58321822
Holy fucking shit your right how didn't I notice that before ahhhhh welp time to go back to the drawing board and figure this out, thanks anon.
>>
>>58321858
Why would you fill an array with just one number?
Other than optimisation or security, I can't imagine.
>>
>>58321874
It's ment to be filled with 90 numbers from the caller but due to my own autism I never noticed that the number would just change every time
>>
>>58316985
Because I wrote it at 6:45 AM, okay?
>>
>>58322364
I-I was just confused; I don't even know enough about whatever language that was to identify it, so I thought there was something weird going on that I didn't understand
>>
>>58323025
It's just dependent type pseudocode.
>>
>>58323104
\(your:mom).\(is:your).pseudocode
>>
What are benefits of closures?
>>
>>58325781
lambda calculus
>>
>>58325781
Capturing scopes in one line of code.
>>
>>58315422
Object oriented is a paradigm. "Object oriented languages" simply include built-in features to enforce OOP rules on the programmer.

You can write object-oriented code in any language, it's just up to you to enforce rules on yourself because your compiler won't help you out.
>>
>>58301640
If this was a daily human language thread OP would post information about ancient tribal languages that have been dead for hundreds of years.
>>
is there a non-meme functional language?
>>
>>58326336
Haskell
>>
>>58326336
OCaml
>>
>>58326501
meme
>>
>>58326091
Elaborate please
Thread posts: 100
Thread images: 9


[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.