Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE ScopedTypeVariables #-}
-- | A ResourceT-based way to use connections with conduit.
module Data.Conduit.Network.Resource where
import qualified Network.Socket as NS
import Control.Exception
import Control.Monad.IO.Class
import Control.Monad.Trans.Resource
@chrisdone
chrisdone / out.json
Created January 25, 2020 16:47
stack bios
{
"packages": [
{
"components": [
{
"modules": [
{
"path": "/home/chris/Work/fpco/stack/src/Control/Concurrent/Execute.hs",
"name": "Control.Concurrent.Execute"
},
@chrisdone
chrisdone / Lexx.hs
Last active January 14, 2020 15:22
Lexx - Show printer
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
-- | Show instance lexer and pretty-printer.
module Lexx where
import Control.Monad.State
@chrisdone
chrisdone / 0README.md
Last active December 27, 2019 14:33
Build kafka docs
<script src="templates/diffDOM.js"></script>
<script>
var before = document.createElement('div');
before.innerHTML = "<p>Hello, World!: 1</p><input type='text'>";
before.childNodes[1].value = "Hello, World!"
console.log('Output: %o', before.childNodes[1].value);
var after = document.createElement('div');
after.innerHTML = "<p>Hello, World: 2</p><input type='text'><p>Whassup?</p>";
@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)
@chrisdone
chrisdone / process-ffi-proposal.md
Last active December 1, 2019 13:05
Proposal: Foreign Function Interface for Processes

Proposal: Foreign Function Interface for Processes

Background

Thread with some poorly put together thoughts.

Limitations of Process Arguments

  • Finite: All inputs to a program are finite. In every mainstream OS, arguments are a string of limited size. They are not
@chrisdone
chrisdone / build.Dockerfile
Last active November 29, 2019 11:30
Testing stack master
FROM debian:9-slim
MAINTAINER Chris Done
################################################################################
# Haskell system dependencies (basically never changes)
RUN apt-get update && \
apt-get install -yq --no-install-suggests --no-install-recommends --force-yes -y -qq \
netbase git ca-certificates xz-utils build-essential curl unzip libgmp-dev
@chrisdone
chrisdone / texp-num.hs
Last active November 27, 2019 18:33
TExp Num?
instance Num a => Num (Q (TExp (SomeNamedWith IsNonzero a))) where
fromInteger 0 = error "It's zero, fool!"
fromInteger n = [|| someNamedWith IsNonzero (fromInteger n) ||]
fine :: Double
fine =
case $$(1) :: SomeNamedWith IsNonzero Double of
(SomeNamedWith p divisor) ->
divide p 123 divisor
@chrisdone
chrisdone / Intro.md
Last active April 10, 2023 06:33
Statically checked overloaded strings

Statically checked overloaded strings

This gist demonstrates a trick I came up with which is defining IsString for Q (TExp a), where a is lift-able. This allows you to write $$("...") and have the string parsed at compile-time.

On GHC 9, you are able to write $$"..." instead.

This offers a light-weight way to enforce compile-time constraints. It's basically OverloadedStrings with static checks. The inferred return type