# A Note on iHaskell a Kernel for Jupyter Notebook Repository link: https://github.com/IHaskell/IHaskell ## Some Usefull commands for Linux Distros ```bash sudo apt-get install -y python3-pip git libtinfo-dev libzmq3-dev libcairo2-dev libpango1.0-dev libmagic-dev libblas-dev liblapack-dev ``` Download and install base libraries needed to do most stuff. ## Getting Started Make sure to install `stack` first: ```bash curl -sSL https://get.haskellstack.org/ | sh export PATH="/usr/local/bin:$PATH" export PATH="/home/jobrien/.local/bin:$PATH" # make sure to put this in your .bashrc so we can access the stack executable ``` clone the repository and install iHaskell ```bash git clone https://github.com/gibiansky/IHaskell cd IHaskell pip3 install -r requirements.txt stack install --fast ihaskell install --stack ``` you can run it two ways: ```bash stack exec jupyter -- notebook --no-browser # or jupyter notebook --no-browser ``` ## Additional Information ### Global stack config If you can't build anything that your machine does have permission to on a certain path then add this to your `config.yaml` in your `.stack` directory. ```bash allow-different-user: true ``` ### Comment #792 on adding packages with iHaskell Check out the [repository](https://github.com/vaibhavsagar/advent-of-code/tree/36fd476fada496bf31c1633df51086b20a58d050/2017) for reference. I'm not aware of a way to pass --notebook-dir and also use the stack.yaml of IHaskell's build directory. If I can suggest an alternative workflow: Set up your notebook directory as a Stack project with your preferred resolver: ```bash $ stack new <notebook-dir> --resolver=<resolver> ``` Launch IHaskell from your notebook directory: ```bash $ cd <notebook-dir> $ stack exec -- jupyter notebook ``` This will use the stack.yaml of your notebook directory, and should be free of issues as long as your resolver and your build of IHaskell use the same version of GHC. An advantage of this approach is that you can add additional packages to the .cabal file that `stack init` generates, run `stack build`, and then use those packages in IHaskell. This is what I did for AoC last year, which it looks like you're also using IHaskell for 😄. If you want even more isolation, I'd suggest checking out the Nix approach, which I personally use and love. Here's an example of my AoC directory for this year. I use this as follows: ```bash $ cd ~/code/advent-of-code/2017 $ nix-build $ result/bin/ihaskell-notebook ``` and it launches a fully-configured IHaskell environment with the additional packages that I have configured. I especially like this because I'm using three different laptops this year and I can have an identically-configured IHaskell environment on all of them just by synchronising my repository and running nix-build. Hope this helps! ## iHaskell Cabal Template for Custom Packages We need to match the ressolver of the version in the iHaskell `stack.ymal` located in the repository for it to use the correct corresponding GHC version that the kernal is using. ```bash stack new exercises --resolver=lts-18.27 #current stack version in the repo ``` ```cabal cabal-version: 1.12 name: exercises version: 0.1.0.0 description: exercises for haskell programming from first principles chapter 16 author: Jack O'Brien maintainer: jack@yumi.ai copyright: 2022 Jack O'Brien build-type: Simple extra-source-files: README.md source-repository head type: git location: https://github.com/githubuser/exercises library build-depends: base >=4.7 && <5, QuickCheck, hspec default-language: Haskell2010 ``` Default `stack.yaml` file: ```yaml # This file was automatically generated by 'stack init' # # Some commonly used options have been documented as comments in this file. # For advanced use and comprehensive documentation of the format, please see: # https://docs.haskellstack.org/en/stable/yaml_configuration/ # Resolver to choose a 'specific' stackage snapshot or a compiler version. # A snapshot resolver dictates the compiler version and the set of packages # to be used for project dependencies. For example: # # resolver: lts-3.5 # resolver: nightly-2015-09-21 # resolver: ghc-7.10.2 # # The location of a snapshot can be provided as a file or url. Stack assumes # a snapshot provided as a file might change, whereas a url resource does not. # # resolver: ./custom-snapshot.yaml # resolver: https://example.com/snapshots/2018-01-01.yaml resolver: lts-18.27 # User packages to be built. # Various formats can be used as shown in the example below. # # packages: # - some-directory # - https://example.com/foo/bar/baz-0.0.2.tar.gz # subdirs: # - auto-update # - wai packages: - . # Dependency packages to be pulled from upstream that are not in the resolver. # These entries can reference officially published versions as well as # forks / in-progress versions pinned to a git hash. For example: # # extra-deps: # - acme-missiles-0.3 # - git: https://github.com/commercialhaskell/stack.git # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a # # extra-deps: [] # Override default flag values for local packages and extra-deps # flags: {} # Extra package databases containing global packages # extra-package-dbs: [] # Control whether we use the GHC we find on the path # system-ghc: true # # Require a specific version of stack, using version ranges # require-stack-version: -any # Default # require-stack-version: ">=2.7" # # Override the architecture used by stack, especially useful on Windows # arch: i386 # arch: x86_64 # # Extra directories used by stack for building # extra-include-dirs: [/path/to/dir] # extra-lib-dirs: [/path/to/dir] # # Allow a newer minor version of GHC than the snapshot specifies # compiler-check: newer-minor ``` ### Installing with Stack on Apple Silicon (ARM64) if you installed using homebrew then you will have a error when installing ihaskell as it's trying to get a library it did not expect on a givin PATH. you will have to include the extra libraries for it to recognise when brew installed all it's casks and stuff. ```bash stack install --fast --extra-include-dirs=${HOMEBREW_PREFIX}/include --extra-lib-dirs=${HOMEBREW_PREFIX}/lib ``` This is included in the repo readme but I was unsure if it was a solution for arm64 proccessors.