Skip to content

Instantly share code, notes, and snippets.

#! /usr/bin/env stack
-- stack --resolver lts-17.0 script
{-# language OverloadedStrings #-}
import qualified Control.Exception as Exception
import qualified Control.Monad as Monad
import qualified Data.Function as Function
import qualified Data.IORef as IORef
import qualified Database.MongoDB as Mongo
import qualified Data.Text as Text
import qualified GHC.Clock as Clock
{-
benchmarked show
time 18.81 ns (18.78 ns .. 18.85 ns)
1.000 R² (1.000 R² .. 1.000 R²)
mean 18.80 ns (18.79 ns .. 18.82 ns)
std dev 41.27 ps (27.30 ps .. 70.30 ps)
benchmarked printf
time 338.0 ns (334.5 ns .. 341.2 ns)
0.999 R² (0.999 R² .. 1.000 R²)
@tfausak
tfausak / stack.yaml
Created December 31, 2020 18:56
GHC 9.0.1 RC1
# The GHC team announced the first release candidate for the 9.0.1 release of
# GHC: https://discourse.haskell.org/t/glasgow-haskell-compiler-9-0-1-rc1-now-available/1706
#
# This is an example `stack.yaml` file that you can use to try out the release
# candidate. Save this file in your current directory and run `stack setup`.
# After that you should be able to use Stack as normal, including
# `stack exec ghci` and `stack build`.
#
# If for whatever reason you don't want to use Stack, you can download the
# official release tarballs at: https://downloads.haskell.org/ghc/9.0.1-rc1/
import qualified Data.IntMap as IntMap
import qualified Data.List as List
import qualified Data.Maybe as Maybe
import qualified Data.Ord as Ord
import qualified Data.Text as Text
main = do
print limit
interact
$ show
@tfausak
tfausak / Main.hs
Created November 22, 2020 15:04
2020 State of Haskell Survey
{-# language OverloadedStrings #-}
module Main ( main ) where
import qualified Control.Monad as Monad
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Encode.Pretty as Aeson
import qualified Data.Aeson.Types as Aeson
import qualified Data.Bifunctor as Bifunctor
import qualified Data.ByteString.Lazy as LazyByteString
import qualified Data.Csv as Csv
import qualified Data.HashMap.Strict as HashMap
@tfausak
tfausak / language-extension-examples.hs
Created August 1, 2020 23:36
Minimal examples of Haskell language extensions.
a = a :: Eq b => () -- AllowAmbiguousTypes
a = proc b -> id -< b -- Arrows
a = let !b = () in b -- BangPatterns
a = 0b0 -- BinaryLiterals
a = id do 0 -- BlockArguments
foreign import capi "" a :: ()
class A b where c :: Eq b => b -- ConstrainedClassMethods
type A = Eq -- ConstraintKinds
# -- CPP
import Data.Proxy; a = Proxy :: Proxy True -- DataKinds
{-
this is a little experiment to parse a module with ghc
and extract exports identifiers, top-level declarations, and (documentation) comments
the idea is to use this as a basis for a haddock-like tool
that doesn't require type checking a module in order to run
-}
module Main ( main ) where
import qualified Control.Monad
import qualified DynFlags
/.stack-work/
/output/
/results.csv
/stack.yaml.lock
@tfausak
tfausak / Main.hs
Created February 28, 2020 15:49
Memory usage for various methods of storing Haskell byte strings in PostgreSQL.
-- I am working on a tool that downloads the Hackage index, stores it, and
-- processes it. I am storing the index in PostgreSQL. I want to keep the
-- maximum residency down. I don't care too much about total runtime.
--
-- This file contains a bunch of different operations in various formats. The
-- idea is to get a baseline measurement for each operation (like downloading
-- the index or reading it from a file) and each format (streaming, lazy, or
-- strict). Those measurements can be used to create a minimum memory
-- requirement for the actual tool.
--
@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.