her.esy.fun/src/posts/0011-Haskell-Projects/index.org
Yann Esposito (Yogsototh) 8c85033f8f
Initial plan for 0011
2020-02-11 22:11:38 +01:00

2.9 KiB

Create a new Haskell Project

Writing a Haskell application can be quite challenging. You must know about:

  • setup your coding environment

    • get the right compiler
    • use libraries
    • handle your Haskell tooling, editor/IDE
  • project directory structure and best practices

    • write tests
    • benchmarks
    • profiling
  • Code architecture

    • encode the data structure
    • manage state and effects

This is both a manual and a tutorial. If you follow it, you should be familiar enough with Haskell to be able to write your own applications. I will focus on command line interfaces and REST APIs.

Haskell Environment Setup

My no brainer solution for it:

  1. Write this shell.nix file and launch nix-shell:

    { nixpkgs ? import (fetchGit {
      name = "nixos-release-19.09";
      url = "https://github.com/NixOS/nixpkgs";
      # obtained via
      # git ls-remote https://github.com/nixos/nixpkgs master
      ref = "refs/heads/nixpkgs-19.09-darwin";
      rev = "d5291756487d70bc336e33512a9baf9fa1788faf";
    }) { config = { allowBroken = true; }; } }:
    let
      inherit (nixpkgs) pkgs;
      inherit (pkgs) haskellPackages;
    
      haskellDeps = ps: with ps; [
        base
        protolude
        containers
      ];
    
      hspkgs = haskellPackages;
    
      ghc = hspkgs.ghcWithPackages haskellDeps;
    
      nixPackages = [
        ghc
        pkgs.gdb
        hspkgs.summoner
        hspkgs.summoner-tui
        haskellPackages.cabal-install
        haskellPackages.ghcid
      ];
    in
    pkgs.stdenv.mkDerivation {
      name = "env";
      buildInputs = nixPackages;
      shellHook = ''
            export PS1="\n\[[hs:\033[1;32m\]\W\[\033[0m\]]> "
         '';
    }
  1. now launch summon-tui

Retrieve Compiler

Dependency Management

Tooling

Haskell Project directoy structure

Tests

Benchmarks

Profiling

Haskell Code Architecture

Basic: IO

Easy: The Handle Pattern

Advanced: MTL

Expert: Free Monad