Templated from hasktorch-skeleton and haskell-template.
Note, ghc 9.8.4 might not be available in a HLS release yet (you can check this in your ghcup tui). But it is available on HLS master as of Mar 2025. To use this, just
ghcup compile hls --ghc 9.8.4 --git-ref master
and everything should work.
- Enable the Hasktorch binary cache using Cachix:
This reduces build time significantly on Linux, didn't work on my macbook when I tested it.
cachix use hasktorch
- Launch a Nix shell, which includes GHC with Hasktorch and Haskell Language Server (hls):
nix develop # You may need to add --extra-experimental-features "nix-command flakes" - Try
ghci, orcabal buildnow! Note,stackdoesn't seem to work, but that's fine, you don't need tostack ghcibecause theghciis in a nix environment with the packages you already need. I.e., you canimport Torchin yourghciand it should work.
For VSCode users, in order to get HLS linting support, you can choose to either
- Launch this repo within the
nixshell that was opened bynix develop, or - Install direnv, call
direnv allowon this repo. When you reopen this repo,direnvwill automatically load.envrc.
Apple uses the MPS backend. There is a toMPS function that deals with this. Try this in your ghci shell:
ghci> Torch.Tensor.toMPS $ Torch.ones' [3,3]Launch Jupyter Notebook in the nix shell:
ihaskell-notebook