Skip to content

Instantly share code, notes, and snippets.

dcastro / slack_edit_message.json
Created May 15, 2022 17:28
"envelope_id": "f34c6197-a7ef-45ed-acad-4d5a3147ec86",
"payload": {
"token": "Pct6Sm6JynybrFXkjEiH7hhX",
"team_id": "T02NDBHSWSG",
"api_app_id": "A03BLN935DK",
"event": {
"type": "message",
"subtype": "message_changed",
"message": {
dcastro / slack_message.json
Created May 15, 2022 17:19
"envelope_id": "012327ef-4c84-41e3-a952-09af25782c17",
"payload": {
"token": "Pct6Sm6JynybrFXkjEiH7hhX",
"team_id": "T02NDBHSWSG",
"api_app_id": "A03BLN935DK",
"event": {
"client_msg_id": "0837851c-2d34-4d4d-804c-7aed753c3421",
"type": "message",
"text": "Hello world",
dcastro / hangzhou.log
Created March 5, 2022 15:49
hangzhou vs ithaca
dcastro /
Last active January 30, 2022 17:32
coffer example log
$ cabal run exe:coffer -- create diogo/google-work \
  --field \
  --field pw:123 \

[SUCCESS] Entry created at '/diogo/google-work'

$ cabal run exe:coffer -- create diogo/google-home \
dcastro /
Last active March 8, 2021 22:31

This tutorial assumes you're already familiar with Haskell's kind system and extensions like DataKinds. If not, please read my blog post first </shameless-plug>.

Say you want to model a TCP connection, and it can be in either an "open" or "closed" status.

data Connection = MkConnection ...
dcastro / log.log
Created February 12, 2021 11:15
nix + custom build type
$ nix-build ci.nix -A all-components --no-out-link
building '/nix/store/bflfb6jrxykrp53fkd5f0gd0d45z776s-git-ls-files.drv'...
trace: To make this a fixed-output derivation but not materialized, set `stack-sha256` to the output of /nix/store/w4f2lcmndg68m64cdrhm1vkhz2s216i7-calculateSha
trace: To materialize the output entirely, pass a writable path as the `materialized` argument and pass that path to /nix/store/y1w6r7c4wrvhllzmz4k3h6g30b4hph74-generateMaterialized
building '/nix/store/36nhcnn93ik0zdsmbcbrpqbq0ajl5lsc-morley-stack-to-nix-pkgs.drv'...
substituteStream(): WARNING: pattern '/nix/store/fn96af9026mkyk28pj3ivwd9drzd247m-morley' doesn't match anything in file '/nix/store/zyzl3v6lww8a81qhmv052075a4qbbj7n-morley-stack-to-nix-pkgs/default.nix'
substituteStream(): WARNING: pattern '/nix/store/fn96af9026mkyk28pj3ivwd9drzd247m-morley' doesn't match anything in file '/nix/store/zyzl3v6lww8a81qhmv052075a4qbbj7n-morley-stack-to-nix-pkgs/pkgs.nix'
these derivations will be built:
dcastro / a.log
Created February 9, 2021 16:36
Doctest + mixins
/home/dc/.ghcup/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too -dynosuf dyn_o -dynhisuf dyn_hi -outputdir /home/dc/dev/other/doctest-mixins/dist-newstyle/build/x86_64-linux/ghc-8.8.3/doctest-mixins- -odir /home/dc/dev/other/doctest-mixins/dist-newstyle/build/x86_64-linux/ghc-8.8.3/doctest-mixins- -hidir /home/dc/dev/other/doctest-mixins/dist-newstyle/build/x86_64-linux/ghc-8.8.3/doctest-mixins- -stubdir /home/dc/dev/other/doctest-mixins/dist-newstyle/build/x86_64-linux/ghc-8.8.3/doctest-mixins- -i -i/home/dc/dev/other/doctest-mixins/dist-newstyle/build/x86_64-linux/ghc-8.8.3/doctest-mixins- -isrc -i/home/dc/dev/other/doctest-mixins/dist-newstyle/build/x86_64-linux/ghc-8.8.3/doctest-mixins- -i/home/dc/dev/other/doctest-mixins/dist-newstyle/build/x86_64-linux/ghc-8.8.3/doctest-mixins- -I/home/dc/dev/other/doctest-mixins/dist-newstyle/build/x86_64-linux/ghc-8.8.3/doctest-mixins-0.1.0
dcastro / rightComb.hs
Last active January 18, 2021 16:02
TyFam inductive case
import Data.Vinyl (Rec(..))
data Tag = TagInt | TagPair Tag Tag
data Exp (t :: Tag) where
EInt :: Int -> Exp 'TagInt
EPair :: Exp t1 -> Exp t2 -> Exp ('TagPair t1 t2)
type family RightComb (tags :: [Tag]) :: Tag where
RightComb '[ x, y ] = 'TagPair x y
dcastro /
Last active February 6, 2022 07:55
Universally vs existentially quantified type variables

A type variable can be either universally ("for all x, then ...") or existentially quantified ("there exists some x, ...").

(If you're a maths persons, this corresponds to ∀x. x and ∃x. x, respectively)

In haskell, universally quantified type vars are represented with a forall:

head :: forall a. [a] -> Maybe a
dcastro / Problem.hs
Last active September 29, 2020 08:20
Capturing type variables in TemplateHaskell
import Language.Haskell.TH.Lib
import Language.Haskell.TH.Syntax
module Problem where
data PP a where
PP :: forall a. Typeable a => PP a
instance Lift (PP a) where
lift PP = [|PP|]