Skip to content

Instantly share code, notes, and snippets.

View dmwit's full-sized avatar

Daniel Wagner dmwit

View GitHub Profile
@dmwit
dmwit / stdin.txt
Last active December 16, 2015 03:09 — forked from anonymous/stdin.txt
{-# LANGUAGE TypeFamilies #-}
type family StateFor a
type instance StateFor Integer = ()
type instance StateFor (a, b) = (StateFor a, StateFor b)
type instance StateFor [a] = (Integer, [StateFor a])
class ReadObj a where
readObj :: StateFor a -> [[String]] -> (a, [[String]])
@dmwit
dmwit / haskell.vim
Created August 20, 2018 12:10
updated haskell.vim for fragamus
let b:align_language_pragma = 0
setlocal cpoptions+=M
iabbrev <buffer> H# {-# #-}<Left><Left><Left><Left>
iabbrev <buffer> HA Applicative
iabbrev <buffer> HB Bounded, Enum, Eq, Ord, Read, Show
iabbrev <buffer> HBS ByteString
iabbrev <buffer> HC Control
iabbrev <buffer> HD Data
iabbrev <buffer> Hd deriving ()<Left>
iabbrev <buffer> Hda data =<CR>deriving (Eq, Ord, Read, Show)<Up><End><Left><Left>
@dmwit
dmwit / test.hs
Created September 14, 2018 20:59
Foo ('A | 'B)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE TypeApplications #-}
data K = A | B | C
data Foo a where
FooAny :: Foo a
FooAB :: Foo (Fam a)
@dmwit
dmwit / lol.hs
Created September 16, 2018 22:53
class Y xs where
type ToS xs :: TreeS
y :: HTree_ (ToS xs) -> HTreeS xs (ToS xs)
instance Y TLeaf where
type ToS TLeaf = TLeafS
y HLeaf_ = x
@dmwit
dmwit / foldb.hs
Created November 3, 2018 02:03
treefold
foldb1 op = foldb' where
pairwise (x:y:rest) = op x y : pairwise rest
pairwise shortList = shortList
foldb' xs@(_:_:_) = foldb' (pairwise xs)
foldb' [x] = x
foldb op def xs = foldb1 op (def:xs)
fs :: Bool -> Int -> Int
fs False = (+1)
fs True = (*3)
vals :: Bool -> Int
vals False = 10
vals True = 20
fOfVals :: Bool -> Int
fOfVals = fs <*> vals
data Zero = Zero deriving Show
data Succ n = Succ deriving Show
class Foo a where foo :: a
instance Foo Zero where foo = Zero
instance Foo n => Foo (Succ n) where foo = Succ
type Two zero = Succ (Succ zero)
type Four zero = Two (Two zero)
type Eight zero = Four (Four zero)
@dmwit
dmwit / whatevs.hs
Last active December 18, 2018 03:58
sublinear indexing with trees
import Data.List
import System.Environment
data SizedTree a = Node Integer a [SizedTree a] deriving (Eq, Ord, Read, Show)
type Stream a = [SizedTree a]
indexT :: Integer -> SizedTree a -> a
indexT 0 (Node _ v _) = v
indexT n (Node _ _ vs) = indexS (n-1) vs
@dmwit
dmwit / wat.hs
Created December 18, 2018 04:01
testing tab settings
import Data.List
import System.Environment
data SizedTree a = Node Integer a [SizedTree a] deriving (Eq, Ord, Read, Show)
type Stream a = [SizedTree a]
indexT :: Integer -> SizedTree a -> a
indexT 0 (Node _ v _) = v
indexT n (Node _ _ vs) = indexS (n-1) vs
@dmwit
dmwit / test.c
Created January 23, 2019 18:01
how to masquerade as somebody else
#include <unistd.h>
int main() {
char *args[3] = {"notsleep", "10", NULL};
return execv("/usr/bin/sleep", args);
}