Skip to content

Instantly share code, notes, and snippets.

@alpmestan
alpmestan / redirect.hs
Created October 17, 2017 12:10
servant redirects, new generation
{-
$ curl -X POST localhost:9876/dog -v
* Connected to localhost (127.0.0.1) port 9876 (#0)
> POST /dog HTTP/1.1
> Host: localhost:9876
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Transfer-Encoding: chunked
@alpmestan
alpmestan / coyo.hs
Last active August 4, 2019 13:54
Coyoneda lemma & fmap fusion
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
import Data.Monoid
import System.Environment
data Coyoneda f a where
Coyoneda :: (b -> a) -> f b -> Coyoneda f a
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by The Glorious Glasgow Haskell Compilation System configure 8.7, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ ./configure --target=aarch64-unknown-linux-gnu
## --------- ##
## Platform. ##
Up to date
]0;Starting...| Run Cc FindCDependencies Stage1: rts/Linker.c => _build/stage1/rts/build/c/Linker.debug_dyn_o.d
| Run Cc FindCDependencies Stage1: rts/RaiseAsync.c => _build/stage1/rts/build/c/RaiseAsync.thr_o.d
| Run Cc FindCDependencies Stage1: rts/WSDeque.c => _build/stage1/rts/build/c/WSDeque.dyn_o.d
| Run Cc FindCDependencies Stage1: rts/sm/Scav_thr.c => _build/stage1/rts/build/c/sm/Scav_thr.thr_debug_o.d
| Run Cc FindCDependencies Stage1: rts/linker/elf_plt_aarch64.c => _build/stage1/rts/build/c/linker/elf_plt_aarch64.thr_dyn_o.d
| Run Cc FindCDependencies Stage1: rts/sm/Storage.c => _build/stage1/rts/build/c/sm/Storage.l_dyn_o.d
| Run Cc FindCDependencies Stage1: rts/Timer.c => _build/stage1/rts/build/c/Timer.thr_dyn_o.d
| Run Cc FindCDependencies Stage1: rts/Hash.c => _build/stage1/rts/build/c/Hash.thr_o.d
| Run Cc FindCDependencies Stage1: rts/RtsFlags.c => _build/stage1/rts/build/c/RtsFlags.o.d
@alpmestan
alpmestan / ghc.diff
Created October 7, 2017 00:39
Adding :kind!! to ghci, for expanding type families _AND_ type synonyms
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index 32e581a10d..b320ef42ce 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -76,6 +76,7 @@ import Linker
import Maybes ( orElse, expectJust )
import NameSet
import Panic hiding ( showException )
+import Type ( expandTypeSynonyms )
import Util
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-- | A simple graph library
module Graph
( -- * Creating graphs
runGraph
, newGraph
, node
@alpmestan
alpmestan / servant-valuelevel.hs
Last active January 2, 2019 23:08
Anonymous """value-level""" servant API type definition
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
import Data.Proxy
import GHC.TypeLits
import Servant.API
infixr 9 >:>
infixr 8 <||>
{ pkgs ? import <nixpkgs> {}
, compiler ? "ghc822"
}:
with pkgs;
let
ghc = haskell.packages.${compiler}.ghcWithPackages (ps: with ps; [ cabal-install ]);
in
---
title: Why is servant a type-level DSL?
author: Alp Mestanogullari
date: 2018-07-43 20:00
toc: true
---
---
This post is an attempt at explaining servant's design as an embedded domain
@alpmestan
alpmestan / servant-flatten.hs
Created January 8, 2018 10:55
Flatten servant API types
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Proxy
import GHC.TypeLits
import Servant.API