Skip to content

Instantly share code, notes, and snippets.

View alpmestan's full-sized avatar

Alp Mestanogullari alpmestan

View GitHub Profile
@alpmestan
alpmestan / coyo.hs
Last active June 17, 2024 15:20
Coyoneda lemma & fmap fusion
{-# LANGUAGE GADTs #-}
import Data.Monoid
import System.Environment
data Coyoneda f a where
Coyoneda :: (b -> a) -> f b -> Coyoneda f a
instance Functor (Coyoneda f) where
fmap f (Coyoneda b2a fb) = Coyoneda (f . b2a) fb
@alpmestan
alpmestan / bla.sh
Created September 11, 2017 08:48
styx
cabal install styx
Warning: The package list for 'hackage.haskell.org' is 26 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
Configuring conduit-1.2.11...
Building conduit-1.2.11...
Installed conduit-1.2.11
Configuring yaml-0.8.23.3...
Building yaml-0.8.23.3...
Installed yaml-0.8.23.3

Keybase proof

I hereby claim:

  • I am alpmestan on github.
  • I am alpmestan (https://keybase.io/alpmestan) on keybase.
  • I have a public key ASD90e7ZU64oz5bgOCJwgXqRtDML5sYiQk_FY0bxl3IyMwo

To claim this, I am signing this object:

@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
@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 / 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 <||>
@alpmestan
alpmestan / config.nix
Created November 6, 2017 13:54
To put in ~/.config/nixpkgs/
{
packageOverrides = ps: rec {
haskell.compiler = ps.haskell.compiler // {
myghc = ps.haskell.compiler.ghcHEAD.overrideDerivation (p: {
src = fetchgit {
url = "git://git.haskell.org/ghc.git";
rev = "commit hash here";
sha256 = "sha that nix computes for this";
};
});
type Flat api = Reassoc (Flatten api)
-- | Completely flattens an API type by applying a few simple transformations.
-- The goal is to end up with an aPI type where things like @a :> (b :<|> c)@
-- are rewritten to @a :> b :<|> a :> c@, so as to have client with very simple
-- types, instead of "nested clients".
type family Flatten (api :: k) :: k where
Flatten ((a :: k) :> (b :<|> c)) = a :> Flatten b :<|> Flatten (a :> c)
Flatten ((a :<|> b) :> c) = a :> Flatten c :<|> (Flatten (b :> c))
Flatten ((a :: k) :> b) = Redex b (Flatten b) a
@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
---
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