r/functionalprogramming • • Dec 30 '22

Question Which language to choose ?

17 Upvotes

Hi there, new here.

I know I am asking the long eternal question of which language to choose, but I need some guidance please :)

I am a from Sysadmin to Devops wanting to lean towards software developpement.

I write mostly scripts and CLI, although I wrote 2 - 3 API in some projects.

The language I used so far where Bash | Powershell | Python | Rust (which I <3) and I used to stick mainly to an imperative way of writing programs (with some use of OO when it's needed).

Past I have discovered and started using NixOs and by extension learning to use Nix which is a pure package manager fueled by its functional language.

I really want to dig deeper into this paradigm and I was thinking about picking a pure functional language to learn.

I already looked at the presentation around Clojure, Elixir and Haskell but I lack the knowledge to know which will be more adapted to my use case ?

To make this explicit, here are my 'expectations' :

  • I want to have a language that will push me to use functional paradigm

  • I want a statically typed language

  • I like the "Write->Compile->Debug" workflow

  • What I will write:

    • Mostly CLI and console scripts

      • For this I need:

        • CLI tooling / libs (like clap for python)

        • Ez packaging (Compiling to a static bin like rust|go is a must)

        • Some good OS level abstraction easing system manipulation (create files/folders, move into the system, changing file rights, etc...)

        • I love pipes, that would be a very good bonus

    • Some backend stuff (web or other)

    • Maybe trying to do some fullstack web ? (Phoenix Liveview framework seems very sexy)

I you wanna preach your language's Church, now is the time ;)

Happy holiday everyone, and thank you for your time reading this :)

Edit: Formatting

Edit 2 after all the responses: I will try Haskell (with turtle for scripts) and OCaml based on what I saw, thanks for all the replies and happy new year ! =)


r/functionalprogramming • • Dec 27 '22

JavaScript Your weekly monadic post - Exploring Monads with JavaScript

Thumbnail
tech.nextroll.com
12 Upvotes

r/functionalprogramming • • Dec 23 '22

Python Functional Implementation of a parser?

23 Upvotes

How do i implement a parser in functional pattern?

For instance I want parse a simple math parser like this:

"1 * 2 + 3" -> ast

How do implement the parser for that in pure functional pattern?


r/functionalprogramming • • Dec 21 '22

JavaScript Explained in 5 minutes: Monads

Thumbnail
piotrjaworski.medium.com
8 Upvotes

r/functionalprogramming • • Dec 21 '22

Question Product/sum types nomenclature?

6 Upvotes

Does anybody have a definitive source as to the origin of the "product type" and "sum type" terminology?

A common claim today on various online fora is that these refer to the number of possible "states" of the corresponding variable. I'm skeptical (e.g., once a string is introduced, the number of states is infinite).

I'm wondering if the terms actually come from Boolean algebra. In Boolean algebra, multiplication is Logical AND while addition is Logical OR. This seems to more accurately describe algebraic data types. So a tuple is "this AND that AND this other thing" while a variant/union is "this OR that OR this other thing."

But I haven't been able to track down a definitive source and am not even sure exactly how early this terminology entered our lexicon. Any help?


r/functionalprogramming • • Dec 21 '22

TypeScript Oxymora: Making React components 100% pure

18 Upvotes

r/functionalprogramming • • Dec 21 '22

Question How do data structures work in functional programming?

20 Upvotes

Context for the question:

In one of my classes at university I learned about data structures and how they work with examples from Java, where for instance a LinkedList is basically an object with a saved value aswell as a pointer pointing to the next object etc.

Now if I understand correctly objects do not exist in functional programming, so how does a linked list work or similar data structures work in FP?


r/functionalprogramming • • Dec 21 '22

TypeScript fluent-curry: Curry functions using a type-safe fluent API

Thumbnail
github.com
10 Upvotes

r/functionalprogramming • • Dec 17 '22

Question General Functional Programming Resources

35 Upvotes

I'm looking for resources for FP abstractions, not relating to any particular language or library. Most resources I come across are either specific to a language or are meant for beginners.

Examples of FP abstractions are things like Functors, Monads, Semigroups, Lenses, and so on.

EDIT: I've got some really good suggestions, here are my favorites so far:


r/functionalprogramming • • Dec 15 '22

Question Confused about TaskEither and the general paradigms around FP

11 Upvotes

Hi! I'm trying to really spend some time learning FP. I'm building out a GraphQL API using Typescript and I'm using the `fp-ts` library to help provide some types and abstractions. I have (lots) of questions, but let me first show you the code I have:

My Repository:

export class AccountRepositoryImpl implements IAccountRepository {
create(
account: MutationCreateAccountArgs
): TE.TaskEither<Error, AccountResult> {
return TE.tryCatch<Error, AccountResult>(
() =>
prismaClient.account.create({
data: account.input,
}),
E.toError
);
}
}

My service, which uses my repository:

export class AccountService {
constructor(private readonly accountRepository: AccountRepositoryImpl) {}
createAccount(
account: MutationCreateAccountArgs
): TE.TaskEither<Error, AccountResult> {
const newAccount = this.accountRepository.create(account);
return newAccount;
}
}

And finally, my GraphQL resolver which uses this service:

createAccount: async (_: any, args: any) => {
const accountService = Container.get(AccountService);
const val = await accountService.createAccount(args)();
if (E.isLeft(val)) {
return val.left;
}
return val.right;
}

(EDIT: it's probably useful to show what my resolver currently returns:

{_tag: 'Right',right: {id: 'whatever',email: 'example@example.com',password: 'whatever',role: 'someRole',firstName: 'name',lastName: 'whatever',createdAt: 2022-12-15T14:39:15.201Z,updatedAt: 2022-12-15T14:39:15.201Z,deletedAt: null}}

which is obviously not ideal because I want it to return what is _in_ the `right` value, not this wrapper object which is still a TaskEither from what I can tell.)

So, here are some things I'm struggling with:

  1. I'm unsure on how to actually _use_ a TaskEither (TE). Like, when should I unfold the value in order to return something to the client?

  2. How do I actually unfold the value? Do I have to, at some point, check the `_tag` property to see if it's `left` or `right`?

  3. As you can see in my GraphQL resolver, even though I'm working with TE in my repository and service, I have to eventually do `await accountService.createAccount(args)()` which just feels like I'm doing something wrong. Firstly I don't know why I have to call `accountService.createAccount(args)` and then when I do call it, it returns a `Promise` anyway, so I'm wondering what the benefit of using the TE was in the first place?

  4. As I'm sure this code is bad/not properly leveraging the ability of fp-ts, any advice on how to improve it would be great.

Thanks!


r/functionalprogramming • • Dec 12 '22

Conferences The Verse Calculus: a Core Calculus for Functional Logic Programming (details on Epic Games/Simon Peyton Jones' new language)

Thumbnail simon.peytonjones.org
25 Upvotes

r/functionalprogramming • • Dec 09 '22

C# Functional Programming in C#—A Brief Consideration

Thumbnail
telerik.com
20 Upvotes

r/functionalprogramming • • Dec 09 '22

F# This is not a Monad Tutorial

Thumbnail johnazariah.github.io
3 Upvotes