Skip to content

Instantly share code, notes, and snippets.

@tfausak
tfausak / normalize-csv.hs
Last active April 2, 2024 20:16
Normalize CSV with Haskell.
#!/usr/bin/env stack
-- stack --resolver lts-8.6 --install-ghc script
import Data.ByteString
import Data.Conduit
import Data.Conduit.Binary
import Data.CSV.Conduit
import System.IO
main = transformCSV
defCSVSettings
@tfausak
tfausak / total.hs
Last active April 2, 2024 20:16
Sums numbers on the command line.
#! /usr/bin/env stack
-- stack --resolver lts-8.15 --install-ghc script --package base
-- Usage:
-- $ echo -e "1.2 3.4\n5.6 not-a-number" | ./total.hs
-- 10.2
import Data.Maybe (mapMaybe)
import Text.Read (readMaybe)
@tfausak
tfausak / invertible-syntax-descriptions.markdown
Last active February 2, 2024 20:58
Survey of invertible syntax description libraries for Haskell.

Invertible syntax descriptions

An "invertible syntax description" is something that can be used to both parse and generate a syntax. For example, instead of defining separate toJson and fromJson functions for a given data type, an invertible syntax description could be used to provide both. There are many Haskell libraries that provide this functionality or something close to it. As far as I can tell most of them are at least inspired by Invertible syntax descriptions by Tillmann Rendel and Klaus Ostermann.

Personally I am interested in using these for HTTP routing. I frequently want to be able to define a route such as /episodes/:id.json, dispatch based on that route, and generate links to that route. Doing so manually is tedious and error prone.

<!doctype html>
<!-- http://taylor.fausak.me/2015/01/27/ios-8-web-apps/ -->
<html>
<head>
<title>iOS 8 web app</title>
<!-- CONFIGURATION -->
@tfausak
tfausak / Dockerfile
Last active July 13, 2023 21:18
Exhibits a libpq bug.
FROM haskell:8.10
RUN apt-get update && apt-get install --yes libpq-dev
ARG USER=haskell
RUN useradd --create-home "$USER"
USER $USER
{
"customizations": {
"vscode": {
"extensions": [
"haskell.haskell"
]
}
},
"dockerComposeFile": "compose.yaml",
"service": "devcontainer",
FROM debian:stable-slim as build
RUN apt-get update && apt-get install --assume-yes \
gcc \
libgmp-dev \
make \
wget \
xz-utils \
zlib1g-dev
compiler-check: match-exact
resolver: ghc-8.0.1.20161117
setup-info:
ghc:
linux64:
8.0.1.20161117:
url: http://downloads.haskell.org/~ghc/8.0.2-rc1/ghc-8.0.1.20161117-x86_64-deb8-linux.tar.xz
content-length: 112047972
sha1: 6a6e4c9c53c71cc84b6966a9f61948542fd2f15a
macosx:
module HW_Answer where
import qualified Data.Text as Text
import qualified Data.Vector as Vector
import qualified HW_Other as Other
data Answer
= Single (Vector.Vector Text.Text)
| Multi Other.Other (Vector.Vector Text.Text)
| Extension (Vector.Vector Text.Text)