Skip to content

Instantly share code, notes, and snippets.

@tfausak
tfausak / DerivingViaPlugin.hs
Last active August 23, 2021 14:13
Cursed Haskell: Deriving via plugin
-- https://downloads.haskell.org/~ghc/9.0.1/docs/html/users_guide/extending_ghc.html#compiler-plugins
-- https://downloads.haskell.org/~ghc/9.0.1/docs/html/libraries/ghc-9.0.1/GHC-Plugins.html
module DerivingViaPlugin where
import qualified Control.Monad as Monad
import qualified GHC.Data.Bag as G
import qualified GHC.Hs as G
import qualified GHC.Plugins as P
import qualified GHC.Types.Basic as G
@tfausak
tfausak / Main.hs
Last active August 7, 2021 13:31
Example of unexpected ambiguity.
#! /usr/bin/env stack
-- stack --resolver ghc-9.0.1 script
-- https://github.com/tfausak/witch/issues/19
{-# language AllowAmbiguousTypes #-}
{-# language ScopedTypeVariables #-}
{-# language TypeApplications #-}
{-# language TypeFamilies #-}
@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
#! /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