Skip to content

Instantly share code, notes, and snippets.

@chrisdone
chrisdone / types.hs
Last active June 11, 2022 23:43
types
{-# LANGUAGE TypeOperators, LambdaCase, StandaloneDeriving, GADTs #-}
data Type env t where
-- A constant type. Add kinds?
-- Maybe, (), Int, Either, (->), etc.
Constructor :: kind -> Type env kind
-- A free variable.
-- a
FreeVariable :: kind -> Type env kind
-- Type application.
@chrisdone
chrisdone / README.md
Last active May 8, 2022 12:29
Template Haskell quickstart

Template Haskell Quick Start

Use the template haskell (abbreviated to "TH") extension in a module with:

{-# LANGUAGE TemplateHaskell #-}

There are a few key pieces of syntax:

@chrisdone
chrisdone / cell-load.hs
Last active May 4, 2022 08:45
Document cell-load pipeline
-- | Load a renamed cell.
resolveRenamedCell ::
Map Hash (Either LoadError LoadedExpression)
-> FillerEnv LoadError
-> IsRenamed (Expression Renamed)
-> RIO DocumentReader (Either LoadError (IsResolved (Expression Resolved)))
resolveRenamedCell globalTypes globalHashes isRenamed = do
hasConstraints <-
pure $
first LoadGenerateError $
@chrisdone
chrisdone / Basic type solver tests.hs
Created May 2, 2022 13:52
Basic unification tests for type checkers
fineGrained :: Spec
fineGrained = do
describe
"Successful"
(do it "a ~ a" (shouldReturn (unifyConstraints' [a .~ a]) (pure []))
it
"Integer ~ Integer"
(shouldReturn (unifyConstraints' [_Integer .~ _Integer]) (pure []))
it
"a ~ b"
@chrisdone
chrisdone / DBAPI.hs
Last active April 10, 2022 07:26
Defaulting fields in a record in Haskell
{-# LANGUAGE DataKinds #-}
-- | My database API.
module DBAPI where
import Data.Defaults
data ConnSpec p = ConnSpec
{ username :: !(Required p String)
22-03-21 13:32:52.939 $ cat /opt/hindent-ormolu
#!/bin/bash
/opt/ormolu-0.1.4.1 \
"--ghc-opt" "-XBangPatterns" \
"--ghc-opt" "-XNumericUnderscores" \
"--ghc-opt" "-XOverloadedLabels" \
"--ghc-opt" "-XPatternSynonyms" \
"--ghc-opt" "-XTypeApplications" \
"--mode" "stdout"
@chrisdone
chrisdone / Parsing.md
Last active February 9, 2022 11:50
Good parser messages with Parsec

Intro

I've been working on a parser for a Haskell-like syntax called Duet. In the implementation I've taken particular care to make an awesome tokenizer and parser that is super helpful to learners.

Jasper Van der Jeugt made a talk about producing good error messages recently, which coincides nicely with my parallel work on this. So I thought I'd also share my

@chrisdone
chrisdone / PrintStgGHC8_4_3.hs
Last active December 6, 2020 18:09
Print STG in GHC 8.4.3
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
-- | Print STG in GHC 8.4.3.
module Main where
import Control.Monad.IO.Class (liftIO)
import qualified CorePrep
@chrisdone
chrisdone / 0README.md
Last active November 8, 2020 09:49
total-eval.hs

Total (non-error-throwing) lambda-calculus evaluators.

@chrisdone
chrisdone / gosper hurwitz.txt
Created October 2, 2018 15:41
precise math numerics
Appendix 2
Continued Fraction Arithmetic
by