大隻雞慢啼

大隻雞慢啼

我們是小國小民,但是我們是好國好民。 - 鄭南榕

01 Jun 2020

SML on macOS

Standard ML on macOS

  • I completed Programming Languages, Part A by Dan Grossman from University of Washington.
  • In Part A, Dan taught us many programming language concepts using Standard ML (SML)
  • Dan is a great teacher and this course definitely deserves 5 stars.

SML Installation

brew cask install smlnj
  • Remember to export the path to SML in bash/zsh:
export PATH=$(brew --prefix)/smlnj/bin:"$PATH"

My REPL-like SML development environment

  • I am too lazy to memorize those Emasc keyboard shortcuts so I decided to create a REPL-like environment by myself. See steps below:
  • Install Visual Studio Code: https://code.visualstudio.com
  • Install Standard ML plugin (not perfect but it works): https://marketplace.visualstudio.com/items?itemName=freebroccolo.sml
  • When you edit SML code in Visual Studio Code, also open a terminal (View -> Terminal) and enter sml (The SML/NJ interactive shell)
    • You can then load the SML file. For example: use "hw3test.sml";
    • Exit the shell by Ctrl+D

(Important) Tune your SML/NJ interactive shell:

  • Note that SML/NJ interactive shell doesn’t support arrow keys so you can’t use up/down to cycle through the history. However, I found a stack overflow post and resolved it by socat
brew install socat

# Then in your .bach_profile or .zshrc, add this alias
alias sml='socat READLINE EXEC:sml'

Cool stuff I learned

  • oneOf type (Option, List). Read more on this: https://reasonablypolymorphic.com/blog/protos-are-wrong/
  • Dynamic scope (where a function is called) vs Lexical scope (where a function is defined), also learned it in R programming.
  • That Java mutation example
  • Pattern matching for function definitions (Function pattern)