/notes

Search IconIcon to open search

Haskell

Last updated July 14, 2022

# ghci

GHCi tip: import Module and :load Module do very different things!

import brings the exports of Module into scope.

:load puts you in the context of that module, including language extensions, everything imported in that module, and non-exported terms from the module

# modelling errors as data types

http://lambdafoo.com/blog/2018/06/22/transformers-either/

# pattern matching

When you see a constructor on the left hand side that’s pattern matching

1
2
k :: Z -> String
k (X s) = s

Alternatively you can use case of

1
2
3
4
l :: Z -> String
l Z = case Z of
  X s -> s
  Y -> "y"

# the tick convention

similar to klass in Java. Used to escape variable bindings

1
data Bool` = True` | False`

# polymorphism

Polmrophic types in haskell always start with a lower case letter. A lower case type means polymorphic [generic]

1
2
i :: a -> a
i x = x

https://qnikst.github.io/posts/2018-10-29-metrics-haskell.html

# profiling

https://medium.com/e-bot7-tech/improving-performance-of-your-haskell-code-with-profiteur-8d2e025b6779 http://neilmitchell.blogspot.com/2018/10/announcing-profiterole-ghc-profile.html?m=1

# Handling Failure

# Maintainability of Haskell Code

# structured logging

# Event Sourcing

# Input Validation

# Configuration Management

# Infrastructure and DevOps Tooling

# Website Application Architecture

# Software Transactional Memory

# Concurrent Programming

# GHC Internals

# Recommended Reading

# Isomorphic Haskell

# Domain Driven Design

# HTTP Clients

# Existential Types

applications.md

# Full Websites

# Webserver and API

Setting up haskell-vim-now on a Cloud9 workspace:

  1. Start with a Blank workspace.
  2. Increase resources (use at least 7GB for disk and 2GB for ram, but more is better).
  3. Edit styles.css to use a powerline font:
1
@import url(https://cdn.rawgit.com/wernight/powerline-web-fonts/f3821a36beeba53e6e937319d4ee636ef30a352c/PowerlineFonts.css);
  1. Update apt:
1
sudo apt-get update
  1. Install the Haskell stack:
1
curl -sSL https://get.haskellstack.org/ | sh
  1. Install haskell-vim-now:
1
2
curl -L https://git.io/haskell-vim-now > /tmp/haskell-vim-now.sh
bash /tmp/haskell-vim-now.sh
  1. Enjoy!

# Optional

Switch to a newer version of node with nvm:

1
2
nvm install 6.9.2
nvm alias default 6.9.2

Uninstall any older versions:

1
2
nvm ls
nvm uninstall 4.6.1

data61.md

Execute nix-shell to bootstrap the environment

Create hello.hs

1
2
x :: Integer
x = 3
1
2
3
4
5
ghci -ignore-dot-ghci 

:load hello.hs #loads from filesystem
:r # reload loaded modules (inc hello.hs)
:t x # obtain type signature of x

# Lists

cons :: https://en.wikipedia.org/wiki/Cons

cons - head and tail

1
2
>> :t (:.)
(:.) :: t -> List t -> List t
1
2
3
>> 1 :. 2 :. 3 :. 4 :. Nil
[1,2,3,4]

The word “cons” and expressions like “to cons onto” are also part of a more general functional programming jargon. Sometimes operators that have a similar purpose, especially in the context of list processing, are pronounced “cons”. (A good example is the :: operator in ML, Scala, F# and Elm or the : operator in Haskell, which adds an element to the beginning of a list.)

# Rosetta

generics :: type variables cons :: https://en.wikipedia.org/wiki/Cons

cons - head and tail

1
2
>> :t (:.)
(:.) :: t -> List t -> List t

# Pattern Matching

Can enable warnings when not all patterns are matched set fwarn-incomplete-patterns see https://stackoverflow.com/questions/31866379/haskell-non-exhaustive-pattern-matching-in-haskell

# Resources

# Lists

const

https://en.wikipedia.org/wiki/Unary_function https://hackage.haskell.org/package/base-4.10.1.0/docs/Prelude.html#v:const

# Point Free

sum' xs = foldr (+) 0 xs

# Workflow

Look at the signature and write down what you have (tm) and write down what you need to get to (tm)

1
2
3
4
data Optional a =
  Full a
  | Empty
  deriving (Eq, Show)
1
2
3
4
5
6
7
What I have                                                                                    
----
x :: a
f :: a -> Optional b
----
What do I need to get to?
? :: Optional b

# People

# Day 1

# Determining file location of a type

1
2
3
>> :i Full
data Optional a = Full a | ...
        -- Defined at src/Course/Optional.hs:15:3

education.md

# Videos

# GC

https://tech-blog.capital-match.com/posts/2-cpu-credits.html

https://github.com/ezyang/compact/blob/master/README.md

# Patterns

https://www.fpcomplete.com/blog/2017/06/readert-design-pattern

# date time

https://hackage.haskell.org/package/auto-update-0.1.4/docs/Control-AutoUpdate.html

# hot paths

https://www.yesodweb.com/blog/2014/08/announcing-auto-update

# compilation

https://rybczak.net/2016/03/26/how-to-reduce-compilation-times-of-haskell-projects/

packages.md

# Caching

https://github.com/SumAll/haskell-cached-io README.md http://blog.wuzzeb.org/full-stack-web-haskell/ tooling.md

# IDE

# Misc

https://begriffs.com/posts/2015-07-27-haskell-source-navigation.html vim.md. https://github.com/begriffs/haskell-vim-now

https://gist.github.com/gatlin/7754289

# GHC Internals


Interactive Graph