Skip to content

Instantly share code, notes, and snippets.

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 / 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";
};
});

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 / 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
-- similar to https://ghc.haskell.org/trac/ghc/ticket/12468
-- except that I'm trying with 8.2.1
GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help
Prelude> :set -XGADTs
Prelude> data Foo a where Foo :: Int -> Foo Bool
Prelude> f :: Foo a -> a ; f (Foo n) = _k n
<interactive>:3:31: error:
• Found hole: _k :: Int -> a
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Proxy
-- could probably use 'reflection' instead of my
-- hacky KnownXXX classes
@alpmestan
alpmestan / Files.hs
Last active August 17, 2016 23:53
File upload with servant
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Files where
import Control.Monad.IO.Class
import Control.Monad.Trans.Either
@alpmestan
alpmestan / gist:8022817
Created December 18, 2013 14:00
output of accelerate-blas-example.hs
$ .cabal-sandbox/bin/accelerate-blas-test
Bus error: 10
$ .cabal-sandbox/bin/accelerate-blas-test +RTS -xc
*** Exception (reporting due to +RTS -xc): (THUNK_1_0), stack trace:
Data.Array.Accelerate.CUDA.Persistent.new,
called from Data.Array.Accelerate.CUDA.State.theState,
called from Data.Array.Accelerate.CUDA.State.CAF
*** Exception (reporting due to +RTS -xc): (THUNK_1_0), stack trace:
Data.Array.Accelerate.CUDA.Persistent.new,
called from Data.Array.Accelerate.CUDA.State.theState,
@alpmestan
alpmestan / mats.hs
Last active December 31, 2015 00:49
accelerate internal error
import qualified Data.Array.Accelerate as A
import qualified Data.Array.Accelerate.CUDA as A
-- (v1 `outer` v2) . (v1 - v2)
h :: A.Vector Double -> A.Vector Double -> A.Vector Double
h v1 v2 = A.run $ accOuter v1' v2' `accApply` A.zipWith (-) v1' v2'
where !v1' = A.use v1
!v2' = A.use v2
-- outer product
@alpmestan
alpmestan / gist:5236437
Created March 25, 2013 11:13
it's "no 'data' week"
{-# LANGUAGE CPP #-}
#define information data
information Dir = Up | Down