Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env nix-shell
#!nix-shell -i runhaskell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [servant-server servant-auth-server servant-streaming-server ])"
#!nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/299814b385d2c1553f60ada8216d3b0af3d8d3c6.tar.gz
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverlappingInstances #-}
@jkarni
jkarni / core
Created December 9, 2016 14:31
ghc-core for non-let-generalized non-firiing
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 186, types: 1,481, coercions: 3,686}
-- RHS size: {terms: 2, types: 0, coercions: 0}
$s$fShowBook'7 :: [Char]
[GblId,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=False, ConLike=False,
WorkFree=False, Expandable=False, Guidance=IF_ARGS [] 40 0}]
@jkarni
jkarni / newrelic.hs
Created January 24, 2016 22:40 — forked from proger/newrelic.hs
debug servant-client requests
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE StandaloneDeriving #-}
module Realm.Newrelic where
import Control.Monad.Trans.Either
import Data.Proxy
{
"paths": {
"/user/{username}": {
"put": {
"parameters": [
{
"type": "string",
"name": "username",
"in": "path",
"required": true
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@jkarni
jkarni / runSqlConn.hs
Last active December 11, 2015 18:16
runSqlConn that works nicely with ExceptT et al
#!/usr/bin/env stack
-- stack --resolver nightly-2015-10-08 runghc --package monadio-unwrappable-0.3
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
import Control.Monad
import Control.Monad.Trans.Class
import Control.Monad.IO.Class
import Control.Monad.Trans.Control
import Control.Monad.Trans.Except
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fdefer-type-errors #-}
module Main where
import Data.Constraint
import Control.Exception
import System.IO.Unsafe
show' y = unsafePerformIO $ do
@jkarni
jkarni / show.hs
Last active September 3, 2015 00:32
{-# LANGUAGE ConstraintKinds #-}
module Main where
import Data.Constraint
show' :: (Maybe (Dict (Show a))) -> a -> String
show' (Just Dict) x = show x
show' Nothing _ = "<<not showable>>"
t1 = show' (Just Dict) 5
-- first a separate class to interpret the access/permission DSL
class IsAccess a where
getAccess :: Proxy a -> Id -> Bool
-- ^ probably something quite different here. The two main options I see generally
-- are evaluating to some normal form (like AccessType) and not requiring Id, or
-- having Id and then directly evaluating to Bool
-- If you want to be allowed to require other values depending on the type (which I
-- think you do) you'd need an associated type synonym).
instance (IsAccess a, IsAccess b) => IsAccess (a :|| b) where