yilin.wei10
2021-3-9 13:39:34

It struck me quite recently that a fundamental divide exists between ML-like languages which can basically infer all types for you and languages with powerful type-systems which can’t (Haskell, Rust, etc…).


yilin.wei10
2021-3-9 13:40:42

I wonder which type of language is easier to teach?


yilin.wei10
2021-3-9 13:43:16

For those which teach, do you go via the write the type declarations route or everything is automatically inferred for you?


yilin.wei10
2021-3-9 13:45:48

Uh, should clarify for Haskell I mean the subset of Haskell + extensions which people typically use.


sorawee
2021-3-9 13:58:17

Even though your type system fully supports type inference, you probably want to write type annotations anyway, at the very least at the top-level declarations. Two reasons:

  1. It serves as a documentation
  2. It serves as a ground truth.

yilin.wei10
2021-3-9 14:17:06

Definitely for anything which is exported between boundaries; I’d also add a third, which is related to 2. which is that with languages with powerful compile-time dispatch it can help guard against “spooky” action at a distance.


yilin.wei10
2021-3-9 14:17:52

But it definitely feels like there’s a ton of busywork, esp. where you require annotations for anything apart from variables within a function body.


ben.knoble
2021-3-9 14:52:17

I’ve written a hefty amount of SML, and even in that you occasionally need type annotations to compile. I’ve never taught it, but I tend to code/experiment as “leave off the types” and then make a pass later when things are more set to add annotations back.


samth
2021-3-9 15:02:46

I don’t understand what the distinction you’re making is. Haskell and SML do basically the same amount of inference, and Rust is also similar but syntactically restricts inference to force you to write more annotations that it could theoretically infer.


yilin.wei10
2021-3-9 16:58:29

@samth I meant distinction in terms of culture/development loop. In ML it doesn’t seem that you write the type signatures out during development like @ben.knoble alludes to. But in Haskell, many of the libraries mean you pretty much have to write out the top-level signatures since it doesn’t infer them - especially when dealing with some of the more hairy encodings which rely on universal quantification.


samth
2021-3-9 16:59:14

I think modern OCaml culture writes similar amounts of signatures to modern Haskell


yilin.wei10
2021-3-9 17:00:02

Maybe it’s just because I’m looking though the intro materials to F sharp/Bucklescript/Elm then.


yilin.wei10
2021-3-9 17:25:28

Oh and ofc, at the extreme end you have Agda and Idris which you use the types to generate the code.


yilin.wei10
2021-3-9 17:29:36

Though I think you’re right @samth, I’m significantly more familiar with one than another, so it’s not right for me to make a sweeping statement.