Live data from Hacker News

Functional programmers need to take a look at Zig

pure-systems.org

31–40 of 163 posts

Re: Functional programmers need to take a look at Zig

#31
post #10

A functional programmer who casts away proper sum types and pattern matching is no functional programmer at all

I thought lisps were all functional programming, and lack sum types and pattern matching? In which case, what's the term for the "proper sum types and pattern matching" flavour of things?

(Pure) expression orientation is the true marker of FP

Re: Functional programmers need to take a look at Zig

#32
These days I just use a few languages:

1. Go, when I first saw code I wrote almost a decade ago still compiles and runs in Go, I decided to use Go for everything. There were some initial troubles when I started using it a decade ago, but now it's painless.

2. Haskell, I use it for DSL and state machines.

3. Bash for all deployment scripts and everything.

4. TypeScript, well for the frontend.

Lately, I’ve been using Go and SQLite for nearly everything.

I don't think I’ve any motivation to look at any other language.

I gave up on Java, Python, Ruby, Rust, C++, and C# long ago.

Fun fact:

Same thing for cloud, I just don't use managed cloud services anymore. I only use VMs or dedicated servers. I've found when you want to run a service for decades+, you’ve got to run your own service if you want it not to cost a lot in the long run.

I manage a few MongoDB, PostgreSQL clusters. Most of the apps like email lists marketer (for marketing, sending thousands of email each day) are simple Go app + SQLite using less than 512MB RAM.

Same for SaaS billing, the solution is entirely written in Go and uses Postgres. (I didn’t feel safe here using SQLite for this for a multi-tenant setup.)

Our chat/ticketing system is SQLite + Go. Deployment is easy, just upload Go cross-compiled binary + systemd service file, alloy picks up log and drops it graphana which has all alerts there.

I don't need to worry about "speed" for anything I do in Go, unlike Ruby/Python.

When something has to be correct I define it model it in Haskell as its rich type system helps you write correct code. Though setup is not painless as Go, decent performance.

I write good documentation, deployment instructions right into mono repo. For a small team this is more than enough imho.

No Docker, no Kubernetes, just using simple scripts + graphana + prometheus + Loki and for alloy/nodeexporter. Life couldn't be any simpler than this.

Re: Functional programmers need to take a look at Zig

#33

I don’t get it Why write: EqPoint.eql(a, c) When you can write: Point.eql(a, c)

I believe EqPoint allows you to pass around a bag of functions (aka an interface, which Zig does not have as a concept) to functions which can be written in terms of "I need these functions" rather than in terms of a concrete type.

Re: Functional programmers need to take a look at Zig

#34
post #10

A functional programmer who casts away proper sum types and pattern matching is no functional programmer at all

I thought lisps were all functional programming, and lack sum types and pattern matching? In which case, what's the term for the "proper sum types and pattern matching" flavour of things?

I think the lisp situation is peculiar, for 3 main reasons:

- most of them are dynamically typed (thus don't need sum types, as there are no types). The ones that do have gradual type systems likely either implement some form of them (off the top of my head I can only remember typed racket, and I think it implements them through union types)

- not all lisps lean functional: I believe that's mostly a prerogative of scheme and clojure (and their descendants); something like CL is a lot more procedural, iirc

- in most lisps, thanks to macros, you probably don't need the language to support some sort of match construct out of the box: just implement it as a macro [1]

In general the "proper sum types" side of functional programming is just the statically typed one, but even in dynamically typed FP languages you end up adopting sum type-esque patterns, like elixir's error handling (which closely resembles the usual Either/Result type, just built out of tuples and atoms rather than a predefined type), and I assume many lisps adopt similar patterns as well

[1] https://github.com/clojure/core.match

Re: Functional programmers need to take a look at Zig

#35
> Well, I’ve been radicalized. I’ve learned enough performance-oriented programming to be dissatisfied with the common functional languages (Haskell, OCaml, Common Lisp/Clojure, Scheme) because each of these languages are predicated on the existence of garbage collection and heaps.

I would take another look at Common Lisp if I were the author. Manual memory management is very much an option where you need it.

Re: Functional programmers need to take a look at Zig

#37
comptime is a restricted form of dependent typing.

In addition to the normal value to value, type to type, and type to value functions, in comptime, you can write static value to type functions.

In full dependent type, you can in addition write dynamic value to type functions, completing the value to type corner.

So in terms of typing strength, plain Haskell < Zig < dependent type languages.

Re: Functional programmers need to take a look at Zig

#38

Earlier quoted context omitted.

Sure, but this is an example from the article, and pertains to sum types in general, not just Maybe.

i dont think its generally a good idea to be making complex type generators like this in zig. just write the type out. the annoyingness of the thing you tried to do in zig is a feature. its a "don't do this, you will confuse the reader" signal. as for optional, its a pattern that is so common that it's worth having builtin optimizations, for example @sizeOf(*T) == @sizeOf(usize) but @sizeOf(?*T) != @sizeOf(?usize). i…

The point is that algebraic data types are common in functional languages. "Maybe" is just an example of an algebraic data type, there's tons more.

If the article says "functional programmers should take a look at Zig", and Zig makes algebraic data types hard, then maybe they shouldn't use it.

If you even say "the annoyingness is a feature, use zig the way it is intended to be used" then that's another signal for functional programmers that they won't be able to use zig the same way they use functional languages.

Re: Functional programmers need to take a look at Zig

#39

These days I just use a few languages: 1. Go, when I first saw code I wrote almost a decade ago still compiles and runs in Go, I decided to use Go for everything. There were some initial troubles when I started using it a decade ago, but now it's painless. 2. Haskell, I use it for DSL and state machines. 3. Bash for all deployment scripts and everything. 4. TypeScript, well for the frontend. Lately, I’ve been using G…

Why did you give up on Java and Rust?

Re: Functional programmers need to take a look at Zig

#40
I've been recently trying to port my simple program to Mojo to find out how the language looks like and feel. And the comptime feature (which inspired by Zig I think) is absolute joy to use. It helps a lot that the syntax looks like Python also. Excited to see how the language will become in the future particularly for its memory safety paradigm.
Post reply on HN