Installing Haskell, using the runtime system. -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- Although you can find some online "try it in the browser!" places, such as replit.com/languages/haskell (where you can use ghci), in order to save your work and not have it publicly findable(!), you will need to install it. Working on zeus: Haskell 8.2.2 is installed on zeus. This is fine for our earlier work; you might have some trouble with libraries and concurrent code, so I'd strongly suggest getting it installed locally at the start, and get used to your programming environment. -------------------------------------------------------------------------------- Installing GHC The GHC installation page has been updated and now suggests that all platforms use GHCUP as the installation path: https://www.haskell.org/ghcup/ the version offered is current enough for our class; last I checked that is 8.10.7, but anything 8.x or greater should be fine. - Windows users, look below for some preparation steps that might ultimately save you time. - Mac/Unix/Windows: https://www.haskell.org/ghcup/ - ghcup upgrade - ghcup install ghc 8.8.4 - ghcup set ghc 8.8.4 Alternate Older Path: - Windows: https://chocolatey.org/packages/ghc/8.8.4 - choco install ghc --version=8.8.4 - Then you can run the terminal command: ghc-8.8.4 -------------------------------------------------------------------------------- Windows: You likely will want PowerShell and MSys2 as well, before installing GHC. However, PS is often already there, and ghcup can help you find Msys2. - install PowerShell (likely already available) - install Msys2 (try GHCUp first, as it should help you here) - note the directory, probably C:\msys64 - use the GHCUP link for Windows installation - https://www.haskell.org/ghcup/ - most default options are good, but don't let it try to install its own Msys2 - give it the directory where you already installed it. - then, you should be able to run cabal (the package manager) instructions in PS. Examples: : cabal update : cabal install mtl --lib : cabal install HUnit --lib -------------------------------------------------------------------------------- Editors: emacs, vim can be good for Haskell. Many students also prefer VSCode. The main goal is to have a whitespace-aware code editor. Setting up VSCode to write Haskell - make sure you have a module declaration at the top of the file. : module Whatever where - extensions: adding a few extensions can enhance your VSCode time with Haskell. You can search the "extension marketplace" for them and install them into VSCode. There are a few you might add. (Incidentally, they are all part of a pack named the "Haskell Extension Pack" - that may be a shortcut to getting all three). - make sure you're using the "Haskell" plugin, e.g. version 1.83+, and not the legacy plugin. This will use the "Haskell Language Server" to provide some type hints and things. - you may also want the "Haskell Syntax Highlighting" extension - "Haskell Linter" will help inline some error and warning messages. -------------------------------------------------------------------------------- Installing packages: - one good route is to install the cabal-install package, and use its commands. - available as part of the Haskell Platform - you can also download the package here (Downloads section), and follow the instructions on the same page under the Readme section: - https://hackage.haskell.org/package/cabal-install - each time you use it, run commands like this, for example to install HUnit, a unit tester framework: - cabal update - cabal list hunit - note the name you want, e.g. HUnit (and not the many other variants/additions for now) - cabal install HUnit --lib - it should automatically download and install dependencies. - include the --lib tag to avoid a warning about seeing no executables in the package (lets cabal know this is fine as you'll only use it as library code) -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- Tip on using more logical cores in Haskell concurrent code Haskell has a way to specify how many cores you'd like your code to run; these are called "Haskell Executable Contexts" (HECs). ghc -threaded -main-is Homework9 -o h9 Homework9.hs ./h8 10 +RTS -N4 -RTS ghc: We first want to compile our code with ghc. -threaded: multithreading, please -main-is Homework9: the main function we want to run isn't in a module named Main, so we specify where that main function is. -o h9: the output should be named h9. Homework9.hs: here's the source code. Then, we run the executable: ./h9: this thing should be executed. (I'm running on mac and on zeus; on windows, likely you'd just have h9). 10: a normal command line argument. +RTS ... -RTS: between these is where you can pass "runtime system" arguments. -N4: the number of HECs should be four, please. I've run this successfully on my own machine (mac) and on zeus.  If you don't use this approach, it's likely that the way your code's logical threads get scheduled may be a bit more (too) predictable, but it's not something you *have* to do to run haskell code.