[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: file.png (44 KB, 700x480)
44 KB
44 KB PNG
Functional programming (FP) is an approach to software development that uses pure functions to create maintainable software. In other words, building programs by applying and composing functions.

Some official websites
>https://www.haskell.org/
>https://www.erlang.org/
>https://elixir-lang.org/
>https://clojure.org/

Use Nix (a purely functional package manager) and NixOS (the OS based on the purely functional package manager)
>https://nixos.org/download/
>https://nixos.org/blog/
>https://search.nixos.org/packages

Where to find jobs
>https://functional.works-hub.com/haskell-jobs
>https://functional.works-hub.com/clojure-jobs
>https://www.indeed.com/q-haskell-developer-jobs.html
>https://www.devjobsscanner.com/haskell-jobs/

Where to learn about functional programming
>https://www.youtube.com/watch?v=bXM5wfQsPn0
>https://edu.anarcho-copy.org/Programming%20Languages/Haskell/Learn%20You%20a%20Haskell%20for%20Great%20Good.pdf
>https://www.haskell.org/tutorial/haskell-98-tutorial.pdf (For Haskell 98)
>https://github.com/clojurians-org/haskell-ebook/blob/master/Parallel%20and%20Concurrent%20Programming%20in%20Haskell.pdf
>https://www.haskell.org/documentation/
>https://clojure.org/guides/learn/clojure
>https://www.erlang.org/doc/system_principles/system_principles.html

Some nice extensions, plugins etc
>https://github.com/haskell/lsp (LSP for Haskell Programming Language)
>https://github.com/mrcjkb/haskell-tools.nvim
>https://github.com/clojure-emacs/cider (Cider for Emacs)
>https://marketplace.visualstudio.com/items?itemName=avli.clojure (Clojure nREPL for VSc*de)
>>
>>100335977
First for lying to people about quicksort
quicksort1 :: (Ord a) => [a] -> [a]
quicksort1 [] = []
quicksort1 (x:xs) =
let smallerSorted = quicksort1 [a | a <- xs, a <= x]
biggerSorted = quicksort1 [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted
>>
This is the definition of art:
fib n = go n (0,1)
where
go !n (!a, !b) | n==0 = a
| otherwise = go (n-1) (b, a+b)


And this is the definition of masterpiece:
import Control.Monad.State
fib n = flip evalState (0,1) $ do
forM [0..(n-1)] $ \_ -> do
(a,b) <- get
put (b,a+b)
(a,b) <- get
return a
>>
 rp([(case N of N when N rem 15==0 -> fizzbuzz; N when N rem 5==0 ->buzz; N when N rem 3==0 -> fizz; _ -> N end) || N <-lists:seq(1, 20)]).
>>
File: fizz.webm (599 KB, 1280x720)
599 KB
599 KB WEBM
>>100337609
>>
>>100335977
Why would I learn Haskell if I want to actually make something? Serious answers ONLY.
>>
>>100339583
so you can learn how to do autistic type tetris that you can't ever actually use in a mainstream language
>>
>>100339555
Yikes!
>>
File: monad.jpg (121 KB, 500x567)
121 KB
121 KB JPG
>>100339555
How is this different from directly using Dart/Flutter? I mean, it's not like you got rid from the bloat. Is it just for the "developer experience"? Honest question.
>>100339583
>actually make something
It depends on what you consider "something". There's plenty of researchers publishing math/programming papers using Haskell. If "something" means commercial/industrial software, then I think you have to consider using other languages. But if you're into computer science and you like functional programming, maybe Haskell would be a great option for you.
>>
>>100339583
to learn FP in a strict environment where you can't cheat. then use a more practical language like Elixir
>>
>>100335977
I'd add Scala to the list, especially because of frameworks like https://zio.dev
There's also https://effect.website for typescript which has a lower entry barrier if someone already knows the lang
>>
>>100335977
>https://clojure.org/guides/learn/clojure
>https://marketplace.visualstudio.com/items?itemName=avli.clojure
The tutorials on the official Clojure site are not well-written, and nobody uses Avli anymore. Here's a good intro to the language:
https://youtu.be/C-kF25fWTO8?t=140s
And here are links to reference docs, tutorials, editor plug-ins, community sites etc.:
https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f

>>100341960
>How is this different from directly using Dart/Flutter?
The main point is to have your front-end stuff in the same language as the back-end. Dart is utterly useless for anything that isn't Flutter, whereas JVM Clojure is a versatile tool with many use cases.

The code for the same program also usually ends up being a lot shorter and simpler, and the syntax looks cleaner with less braces and commas and semicolons and so on. Thanks to Clojure's macro support, some of the most annoying things about Flutter have also been done away with, so for example now you don't have to write "child:" every time you stick one widget into another.
Here's a side-by-side comparison of the same app in Dart and ClojureDart:
https://github.com/flutter/codelabs/blob/main/namer/step_08/lib/main.dart

https://github.com/Tensegritics/ClojureDart/blob/main/samples/first_flutter_app_codelabs/src/sample/first_flutter_app_codelabs.cljd

>I mean, it's not like you got rid from the bloat.
I have no idea what impact CLJD has on performance. It transpiles to Dart, which naturally incurs some overhead. However, React was for a long time much faster in ClojureScript than in plain Javascript, because it turns out that using a language that avoids mutation is a great boon when your interface library has to redraw everything that is mutated.
Looking at the Dart output of the ClojureDart compiler, basically every variable is marked as either const or final.
>>
>>100335977
https://ocaml.org/
>>
>>100347590
why use ocaml when F# exists?
>>
>>100348706
why use F# when Haskell exists?
>>
>>100335977
Great beginner Haskell book (free online):

https://learnyouahaskell.com/
>>
>>100350354
why use Haskell when SML exists?
>>
>>100339583
To make imperilards cry and shit their pants
>>
>>100335977
You should add this to the op
https://fsharpforfunandprofit.com/site-contents/
>>
>>100350993
why use SML when FP exists?
>>
are there any functional game engines? how do they perform compared to OO?
>>
>>100351672
Functional Programming is actually a game engine... I recommend trying Haskell, it's F2P
>>
fact: there are 0 real practical advantages to functional programming over imperative
it is just mental masturbation for the bottom of the high iq range
>>
so functional programming is just spergs jerking off about math?
>>
>>100351873
the fact that it's hard for you, does not mean there are no advantages.

it's ok friend, not everyone needs to be smart. we all give what we can in life, and most importantly, have a good time!
>>
>>100335977
Isn't JavaScript functional too
>>
>>100352304
I never said it was hard and the fact that youre so eager to make this into an opportunity to assert how smart you are only proves my point
you also never addressed my first point, because Im right and you have no argument
>>
Distilled, pure functional programming should use floor functions as If conditional statements.
>>
File: lazy-fizzer.png (49 KB, 556x570)
49 KB
49 KB PNG
>>100337609
>>100339555
>>
>>100351873
FP is one strategy for managing complexity in a sprawling codebase. When most of your codebase is written in an FP style, you don't have to worry about global state changing in unexpected ways. It simplifies the logic.

>>100351879
>so functional programming is just spergs jerking off about math?
No, that's just the Haskell/Idris crowd.

Practical FP languages like Elm, Ocaml/F#, Clojure(Script) and so on are used by real companies doing useful things, mostly for finance and webshit.

>>100351672
>are there any functional game engines?
John Carmack has said and written quite a bit about using functional techniques in game programming:
http://www.sevangelatos.com/john-carmack-on/

As far as game engines in functional languages: None that I know of. The editor, tooling etc. of https://defold.com is written in Clojure, but the engine itself is written in C/C++. If you were to count Rust as functional then there probably are some.
>>
File: fizzbuzz.png (120 KB, 996x836)
120 KB
120 KB PNG
>>100353470
>>
>>100353656
*跪いています*
>>
File: file.png (254 KB, 647x911)
254 KB
254 KB PNG
>>100353645
>Clojure(Script) and so on are used by real companies doing useful things
By the way, Nubank uses Clojure and Schema in their core system. See picrel
>>
>>100354079
Yeah, NuBank is the biggest sponsor of Clojure development, almost the entire core team is or was employed by them, including language creator Rich Hickey until he retired last year.

Their Database system, Datomic, is another Clojure meme. It uses Datalog instead of SQL:
https://www.learndatalogtoday.org/
>>
>>100353656
Can uhhh we have an explanation?
Pretty please?
>>
-module(fizzbuzz).
-export([start/1]).

start(N) -> fizzbuzz(N, []).

fizzbuzz([], Acc) -> lists:reverse(Acc);
fizzbuzz(N, Acc) ->[H|T]= N, fizzbuzz(T, [modfb(H)|Acc]).


modfb(0) -> 0;
modfb(X) -> mod1(X, X).

mod1(X, Y) when (X > -15) and ( X /= 0) and (X < 15) -> modb(Y);
mod1(0, _) -> fizzbuzz;
mod1(X, _) -> mod1(X rem 15, X).

modb(X) -> mod2(X, X).
mod2(X, Y) when (X > -5) and (X /= 0) and (X < 5) -> modf(Y);
mod2(0, _) -> buzz;
mod2(X, _) -> mod2(X rem 5, X).

modf(X) -> mod3(X, X).
mod3(X, Y) when (X > -3) and (X/= 0) and (X < 3) -> Y;
mod3(0, _) -> fizz;
mod3(X, _) -> mod3(X rem 3, X).
>>
>>100337297
quicksort is about partition, doesn't matter if it's not mutable
>>
>>100351873
How? I find functional programming makes it very easy to write clear and concise programs.
>>
Is jq, a json mangling DSL that's quite robust, more of a functional language or an array language?
>>
>>100337297
>>100356173
What's worse: quicksort's strength lies in its space efficiency, which is not present here. This is a facetious implementation
>>
>>100355814
sure, I can write a line-by-line explanation of what it does later (I'm on my phone right now).
If you just want to verify that it actually works, you can copy-paste it into a Clojure repl from here:
https://odysee.com/@cheatsheets:a/fizzbuzz:c
>>
>>100356452
like I said, it's about partition
>>
>>100351025
dead lang
>>
>>100357335
no u
>>
>>100335977
why do you fp_troons need a three separate threads at any single time
YWNBAComputerScientist
>>
>>100359432
Or a Mathematician
>>
>>100356043
what are you trying to do here?
#! /usr/bin/env escript
main(_) ->
lists:foreach(fun (N) -> io:fwrite("~s\n", [fizzbuzz(N)]) end, lists:seq(1,100)).

fizzbuzz(N) when N rem 15 == 0 -> "FizzBuzz";
fizzbuzz(N) when N rem 3 == 0 -> "Fizz";
fizzbuzz(N) when N rem 5 == 0 -> "Buzz";
fizzbuzz(N) -> integer_to_list(N).
>>
There's some insanely groundbreaking stuff going on in the Clojure world, namely Electric and Rama
>>
>>100359748
I am new, I also couldn't get the rem working in guards (is it because I used = instead of == ?).
>>
>>100341960
no, but what IS a monad really, like in dumby dumb terms?
>>
>>100360767
https://youtube.com/watch?v=C2w45qRc3aU

https://youtube.com/watch?v=ZhuHCtR3xq8
>>
def fuzzbuzz(num):
fizzbuzz = f'for number in range(1,{num}):\n'
for i in range(1,num+1):
if i % 5 == 0 and i % 3 == 0:
fizzbuzz += f' if number == {i}:\n print("{i} FizzBuzz")\n'
elif i % 3 == 0:
fizzbuzz += f' if number == {i}:\n print("{i} Fizz")\n'
elif i % 5 == 0:
fizzbuzz += f' if number == {i}:\n print("{i} Buzz")\n'
else:
fizzbuzz += f' if number == {i}:\n print("{i}")\n'
return fizzbuzz

fizzbuzz = fuzzbuzz(10000)

with open('fizzbuzz.py', 'w') as f:
f.write(fizzbuzz)
f.close()
>>
>>100360851
>functional programming
>if
yikes
>>
>>100359432
why do you oop_troons need a thirty separate threads at any single time?
>>
File: lookma_imuselesstoo.png (16 KB, 1107x518)
16 KB
16 KB PNG
>>100335977
>Fizzbuzzer thread for fizzbuzzing
>nobody being useless in APL yet
sad.
>>
>>100360652
yeah, guards work on booleans, which is what == evaluates to. = is for unification
>>
>>100362966
lol that makes it a lot easier. I am trying to make a multiprocess fizzbuzz. One process for fizz, one for buzz, then maybe one for numbers that arent divisable by 3 or 5
>>
>>100362757
Managed to further convolute it.
>>
>>100362508
>Implying that only OOP fags don't like FP
NTA but I hate you both equally.
>>
>>100363324
What do you like?
>>
>>100363556
Array, proceedural and assembly. I can only stand FP or OOP when they're highly limited and impure.
>>
>>100339555
nice trips. Please post about how you built and deployed this



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

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.