r/functionalprogramming • u/kinow • Mar 21 '23
Intro to FP Mostly adequate guide to FP (in JavaScript)
r/functionalprogramming • u/kinow • Mar 21 '23
r/functionalprogramming • u/vkopaniev • Mar 20 '23
r/functionalprogramming • u/StjepanJ • Mar 20 '23
r/functionalprogramming • u/webvv • Mar 19 '23
r/functionalprogramming • u/mhashim6 • Mar 18 '23
r/functionalprogramming • • Mar 17 '23
Would anyone be willing to write some psuedocode showing me what they think would be the fastest way to do this functionally?
https://i.imgur.com/bnwO5AU.png
Imperatively, using foreach for example, the psuedocode would look something like this:
setY = [];
foreach (setX as memberOfX) {
foreach (memberOfX as memberOfmemberOfX) {
push(setY[memberOfmemberOfX], memberOfX)
}
}I can conceive of some ways to do this with a map() and then a flatten() step but it seemed inefficient. Since this must be so common I'm assuming there must be some blessed, known-to-be-optimal strategy.
Thanks in advance!
Edit: Interestingly, I was able to find this paper from 25 years ago, "Experimental Evaluation and Comparison of Algorithms for Incremental Graph Biconnectivity" which calls this operation "evert" https://www.cs.utexas.edu/~vlr/papers/tr97-17a.pdf The concrete example and algorithm is on page 10.
r/functionalprogramming • u/a-concerned-mother • Mar 17 '23
r/functionalprogramming • u/hunterh0 • Mar 16 '23
The hugging face dataset API mainly handle data manipulation with a map function. However, it looks like they are hacking python to achieve this and it is lacking other functional features. Also it feels clumsy when you need to compose multiple mapping that produce different datatypes. Non the less, it’s a great tool, but it looks like an FP focused language can do better.
I have no experience in FP languages, but it seems that using ”functional programming” to manipulate data makes your code cleaner and shorter. Which language/framework do you recommend that can replace python in at least the data preperation/pipline part? Or maybe adapting python to a more FP style?
r/functionalprogramming • u/grahamhutton • Mar 16 '23
The first ACM SIGPLAN Workshop on "Functional Software Architecture - FP in the Large" will be held in Seattle, USA in September 2023, co-located with the ICFP conference.
Please share, and submit your best papers, experience reports, and architectural pearls on large-scale functional programming!
https://www.functional-architecture.org/events/funarch-2023/cfp/
r/functionalprogramming • u/tennaad • Mar 15 '23
I'm not sure the title really makes what I'm struggling with clear, but hopefully my post will.
I'm struggling to make things look clean and easy to follow when using flow/pipe and the inputs/outputs of functions don't line up nicely.
e.g. this trivial case is fine.
const foo = (n: number) => "";
const bar = (s: string) => true;
pipe(0, foo, bar) // trueThe code in question looks something like this:
const fetchAndDecode = (chip8: Chip8): [Chip8, Opcode] => [
chip8,
Opcode.ClearScreen,
];
const execute =
(opcode: Opcode) =>
(chip8: Chip8): [Chip8, Option<DisplayCommand>] =>
[chip8, option.none];
const decrementDelayTimer = (chip8: Chip8): Chip8 => chip8;
const decrementAudioTimer = (chip8: Chip8): [Chip8, boolean] => [chip8, true];
const cycle: (chip8: Chip8) => [Chip8, boolean, Option<DisplayCommand>] = flow(
fetchAndDecode,
([chip8, opcode]) => execute(opcode)(chip8),
([chip8, display]) => [
...pipe(chip8, decrementDelayTimer, decrementAudioTimer),
display,
]
);The nested pipe looks awkward to me, and execute line isn't exactly the cleanest.
I then tried using the State monad to improve this which resulted in the following:
const fetchAndDecode: State<Chip8, Opcode> = (chip8: Chip8) => [
Opcode.ClearScreen,
chip8,
];
const execute =
(opcode: Opcode): State<Chip8, Option<DisplayCommand>> =>
(chip8: Chip8) =>
[option.none, chip8];
const decrementDelayTimer =
(display: Option<DisplayCommand>): State<Chip8, Option<DisplayCommand>> =>
(chip8: Chip8) =>
[display, chip8];
const decrementAudioTimer =
(
display: Option<DisplayCommand>
): State<Chip8, [Option<DisplayCommand>, Option<AudioCommand>]> =>
(chip8: Chip8) =>
[[display, option.none], chip8];
const cycle = pipe(
fetchAndDecode,
state.chain(execute),
state.chain(decrementDelayTimer),
state.chain(decrementAudioTimer)
);This improves how the pipe looks, but I don't like how decrementDelayTimer and decrementAudioTimer have to accept display only to pass it back out when those functions will never act upon those values.
This is my first time trying to write anything non-trivial in a (as close as possible to purely) functional way and I feel like I'm missing something fundamental.
Could anyone point me in the right direction? Ideally I'd like to learn what I'm missing rather than just have the answer handed to me (although feel free to do that if you wish)
r/functionalprogramming • u/kinow • Mar 14 '23
r/functionalprogramming • u/kinow • Mar 12 '23
r/functionalprogramming • u/kinow • Mar 12 '23
r/functionalprogramming • u/nalaginrut • Mar 12 '23
r/functionalprogramming • u/iliyan-germanov • Mar 10 '23
r/functionalprogramming • u/kinow • Mar 07 '23
r/functionalprogramming • u/Serokell • Mar 07 '23
r/functionalprogramming • u/NullPointer-Except • Mar 05 '23
Hi! I'm currently trying to get a bit more comfortable with languages such as java/js/python (particularly java). And I'm looking for resources/libraries to mock these features into these languages (partly because this would make my transition a bit easier, and partly because my personal developer experience is better having them around c:).
For python I actually found a nice post about typeclasses and another on HKT by the same author! But I struck a wall over java :(.
r/functionalprogramming • u/kinow • Mar 05 '23
r/functionalprogramming • u/ClaudeRubinson • Mar 04 '23
People love Nix for all kinds of reasons and continue to find new applications for it. Please join the Houston Functional Programming Users Group on Wed, March 15 @ 7pm U.S. Central time (Thu, March 16 @ 12:01am) when Gabriella Gonzalez will discuss using Nix as a `make` replacement.
HFPUG meetings are hybrid, so you can join us online or in-person. Details are available on our website at https://hfpug.org.
r/functionalprogramming • u/uppercase_lambda • Mar 02 '23
r/functionalprogramming • u/teepee33 • Mar 01 '23
I am working with a set of functions from an external package which are defined in a "data-first" style, such that they take the 'data' as the first argument, and all other "configuration parameters" as the rest of the arguments.
For purposes of function composition, I wanted to transform these functions into a "data-last" style and have developed a higher-order function that does that by instead defining an outer function that takes all configuration parameters as arguments and then returns a function that takes only the data as an argument and then supplies all arguments to the orginal (i.e., "data-first") function. Here's an example to show what I mean
From the external package, the function signature looks like this, (using python lambda syntax, just because) where data is the data, and the rest of the parameters (a, b, c) are "configuration parameters":
data_first_function = lambda data, a, b, c: #...Instead, I want to have a function that behaves something like this instead (without actually having to define it like this for each case):
data_last_function = lambda a, b, c: lambda data: data_first_function(data, a, b, c)I have worked out the implementation details of a function that can transform any "data-first" function to a "data-last" function without needing to write a new definition like the one I just showed above. Basically in what I believe is point-free style, i.e.:
data_last_function = transform_to_data_last(data_first_function)My question is: is there a name for this type of transformation done by transform_to_data_last? I know it has some elements of currying and partial application, but it doesn't seem to meet the definition of either of those entirely. I want to know if there is a specific term for what the higher-order function transform_to_data_last does.
Any insight would be greatly appreciated, as I would like to assign it the most appropriate name possible.
r/functionalprogramming • u/IamZelenya • Mar 01 '23
I want to clarify referential transparency, why it is so cool, what it has to do with side-effects, and what common misconceptions are. For instance, how can the code have no “side-effects”, but the program can print to the console?
Video: https://youtu.be/UsaduCPLiKc
📹 Hate watching videos? Check out the complementary article on dev.to, which covers the same content.
r/functionalprogramming • u/ibrahimbensalah • Mar 02 '23
based on your experience / interpretation what do you consider to be the fastest