HackerTrans
TopNewTrendsCommentsPastAskShowJobs

brandonspark

no profile record

Submissions

Reviewer First Pull Requests

5xx.engineer
2 points·by brandonspark·letztes Jahr·0 comments

My journey to teaching computer science, functionally

brandonspark.github.io
8 points·by brandonspark·letztes Jahr·1 comments

Securing CodeQL queries using Semgrep

semgrep.dev
11 points·by brandonspark·vor 2 Jahren·2 comments

From SML to OCaml

brandonspark.github.io
5 points·by brandonspark·vor 2 Jahren·0 comments

15-150: Principles of Functional Programming

brandonspark.github.io
448 points·by brandonspark·vor 3 Jahren·126 comments

comments

brandonspark
·vor 10 Monaten·discuss
but still along the same lines as "safer". the stresses are different, "safer" has the stress as "SAY-fer" and "secure" has the stress as "sih-KYOOR". the latter sounds more similar (and rhymes better) with "more", the originator of the phrase "less is more"
brandonspark
·vor 10 Monaten·discuss
missed opportunity for "less is secure"
brandonspark
·letztes Jahr·discuss
I see. This is indeed the in-depth breakdown I was looking for, thank you.
brandonspark
·letztes Jahr·discuss
I was hoping this article would be a little more concrete, but it seems that it largely is talking about the takeaways about functional programming in a philosophical, effort-in vs value-out kind of way. This is valuable, but for people unfamiliar with functional programming I'm not sure that it gives much context for understanding.

I agree with the high-level, though. I find that people (with respect to programming languages) focus far too much on the specific, nitpicky details (whether I use the `let` keyword, whether I have explicit type annotations or type inference). I find the global, project-level benefits to be far more tangible.
brandonspark
·letztes Jahr·discuss
Context: I posted my functional programming lectures to HackerNews some time ago (this thread: https://news.ycombinator.com/item?id=38351195) and finally got around to writing a blog post about my experience teaching functional programming. You can read about my experiences here.
brandonspark
·letztes Jahr·discuss
"Opengrep"? But `grep` is already free...
brandonspark
·letztes Jahr·discuss
thank you!
brandonspark
·vor 2 Jahren·discuss
There's no reason this couldn't be done. Indeed, in OCaml (which I am more familiar with), you could easily define:

```ocaml

type 'a nonempty = Single of 'a | Cons of 'a * 'a nonempty

```

This would be the type of lists that contain one or more elements of the type parameter.

I think it's just convention that typically, when we talk about lists, we are interested in the empty case as well. Finding "all X that satisfy P in Y", as a general computational problem, is _very_ common (consider: filtering a list, querying for a predicate in a collection, finding sequences of moves in a search space), and generally could result in an empty list as a possible output.

In a non-practical sense, if you want the type theory, another reason is you can think of `[a]` as the free monoid on the collection of `a`. In other words, strings of elements of `a`, joined via concatenation. This monoid requires a unit, which is the empty list.
brandonspark
·vor 2 Jahren·discuss
This one makes sense to me, since lists are way more canonically used than arrays in functional languages. I rarely find myself constructing array literals -- I'm far more likely to simply convert from a list.

Though, I agree the semicolon delimiting is regrettable.
brandonspark
·vor 3 Jahren·discuss
Haha, maybe. I'm not looking to earn any money from this, though. Time is the bigger constraint in my life at the moment.
brandonspark
·vor 3 Jahren·discuss
If you get to around lecture 9, a classic example I always tell people to start with is a calculator!

For instance, here's the SML code for it:

``` datatype exp =

    Num of int

  | Plus of exp * exp

  | Minus of exp * exp

  | Times of exp * exp

  | Div of exp * exp

```

Implement the function `eval : exp -> int`, which evaluates the expression as best as it can. Assume no division by zero.

Extra credit: Can you implement `eval' : exp -> int option`, that returns `SOME n` if the expression evaluates, and `NONE` if it divides by zero?
brandonspark
·vor 3 Jahren·discuss
This is Haskell-specific, it sounds like. I agree, the IO monad is really quite inconvenient sometimes.

I work in OCaml, which is also a functional language, but prints can be added in single lines. I address this point in Lecture 19 (Imperative Programming), actually, but my perspective is -- we invented immutability and purity to serve us, but we need not be fanatically beholden to it. In my opinion, I think Haskell goes in that direction, when every usage of IO now needs the IO monad to get involved.

A little mutability is OK. Functional programming is about the avoidance of side effects, more than simply forbidding it.
brandonspark
·vor 3 Jahren·discuss
(but I have thought of developing my own exercises independently to go with the lectures, to post on my website. This is generally a lot of work, though, so this might take some time, depending on how much people would benefit from it.)
brandonspark
·vor 3 Jahren·discuss
Unfortunately, it does not. These lectures are "mine", in the sense that I developed all of them myself, but the homeworks and lab exercises are the combined efforts of generations of TAs and instructors from the past. It wouldn't be right for me to give them away. (they are also reused from time to time, so there are academic integrity concerns with that also)
brandonspark
·vor 3 Jahren·discuss
There's a few things which go into this (hi, I'm the instructor!).

One such reason is historical. Standard ML is a research language, and a significant amount of work on it was done by professors at Carnegie Mellon, who developed the curriculum for this course.

Even setting that aside though, I fully agree with the choice to teach it in SML. For transparency, I work professionally in OCaml, so I am not unfamiliar with it, and I enjoy it quite a bit. That being said, I think that the approach taken by CMU is best summarized as the fact that languages are ephemeral, and the concepts are what matters. We don't teach programming languages, we teach concepts -- so even if SML is not widely used, the tradeoff for having students have a simpler, less distracting, and better learning experience is well worth it.

OCaml has its own intricacies that make things difficult. For instance, you can go down a lot of rabbit holes with `dune` and `utop` and `ocamlc` and `ocamlopt` and all of these things, versus SML/NJ's simple interactive REPL. Another thing is that the language is just generally more "bloated" -- you can teach modules, but then what if a student starts running into first-class modules, recursive modules, or even beyond that, GADTs and classes and objects?

(as an aside, this is my primary reason for why I would not want to teach an introductory course in Haskell. To do anything, you suddenly need to understand the concept of type classes and lazy evaluation, and that's simply too much. I don't know much about the other languages.)

I think teaching is as much enabling students to succeed as it is to prevent them from shooting themselves in the foot. For an anecdote, there is an `Option.valOf` function (of type `'a option -> 'a`), which essentially is just a bad function that should be avoided where possible. Every semester, without fail, even though we never tell students that function exists, students are smart enough to use Google, and will use it anyways, ultimately harming themselves.

I think that same mentality applies to programming language choice, here. Keep it simple, keep it neat, and make sure that the students see what is necessary for their education, and not have to spend mental energy thinking about much more.