r/functionalprogramming • • Apr 28 '24

Question Which Functional Language with strong typing to learn?

My background:

I'm a software engineer working a dayjob with Web development, using essentially just TS for everything

As a side project, I'm working on a game for which I'm using C#, GDScript and a markdown language we're creating called SPML

I've dabbled in some other languages, like C, C++, Rust, Ruby, Java, Python, and some others, but never really got deep into any Functional Programming language.

Recently I've started to learn about Clojure - I'm enjoying it, but I'm feeling the lack of types; coming from TS and Rust, which are my favorite languages so far, it feels so clunky to write anything without types. In Rust and TS I can hover over parameters and variables within functions and know immediately what they are; I hover over functions and I know exactly which type they return, what they take in, etc, and if I try to use something in an awkward way, the compiler lets me know immediately

What I'm looking for:

Essentially a popular strongly typed FP language, that can be as expressive as Clojure. I just want to learn it for myself, not really for looking into jobs, but popularity is important due to availability of packages and learning material. I really liked that on Clojure, but I'm not sure I'll continue learning it after finishing the current book due to the lack of typing

EDIT: Thanks for all the suggestions, everyone!

I'll probably stick to Clojure for a bit after hearing about Babashka; then I'll learn either F#, Haskell or OCaml

32 Upvotes

36 comments sorted by

View all comments

Show parent comment

3

u/[deleted] Apr 29 '24

What do you mean by crazy types?

4

u/rlDruDo Apr 29 '24

The types in haskell give you much stronger guarantees than in other languages. With some language extensions you can define type families and other advanced features that give you even more power.

Haskell uses higher kinded types (in Java you can have generics, which can be Integer, List<Integer>, etc; in Haskell you can have generics over List, Map Integer, Option (they’re not applied to a specific type). Besides Agda et al I only know about Scala that supports them in the same way. You can have ADTs and their generalised version GADT.

You use typeclasses, which are stronger interfaces.

In function signatures you can use something called „rank-n-types“ (I am not sure if the name is actually that) which allow you do something like:

runST :: forall α. (forall s. ST s α) -> α

Where ST is a datatype. This allows for scoped mutability (Haskell can do a lot of mutable stuff), without leaking the mutable variables outside of scope by returning for example.

There is a good book that I habe yet to read: „Thinking with types: Type level programming in Haskell“.

Scala supports similar and other things. But I don’t know enough Scala.

Haskell also has work underway that will introduce dependent types. Scala has some dependent types but I don’t know exactly how.

2

u/[deleted] Apr 29 '24

Thank you for this detailed answer!