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
- Installing SML/NJ in macOS (recommend using homebrew): https://smlnj.org/dist/working/110.96/macos.html
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 entersml(The SML/NJ interactive shell)- You can then load the SML file. For example:
use "hw3test.sml"; - Exit the shell by Ctrl+D
- You can then load the SML file. For example:
(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) vsLexical scope(where a function is defined), also learned it in R programming.- That Java mutation example
- Pattern matching for function definitions (Function pattern)
Links
- SML Basis Library: https://smlfamily.github.io/Basis/overview.html