Skip to content

Instantly share code, notes, and snippets.

View timjb's full-sized avatar

Tim Baumann timjb

View GitHub Profile
{-# LANGUAGE TypeFamilies #-}
type family InvertArrow x :: * where
InvertArrow (a -> b) = b -> a
myId :: InvertArrow (a -> b) -> b -> a
myId x = x
@timjb
timjb / LICENSE.txt
Last active February 12, 2016 00:30
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
-- Draws an image similar to the cover of Okasaki's Purely Functional Data Structures
module Main where
import Diagrams.Backend.SVG.CmdLine
import Diagrams.Prelude
side = sqrt 2
triangleRect :: Diagram B
@timjb
timjb / paley.hs
Last active December 14, 2015 18:55
{-# LANGUAGE BangPatterns #-}
module Paley where
import Data.Function (on)
import Data.List (find, insertBy)
import Data.Maybe (catMaybes)
import Control.Monad (forM_)
-- | Prime numbers
#!/usr/bin/env stack
-- stack --resolver lts-3.11 --install-ghc runghc --package hmatrix-glpk-0.4.1.0
module Main where
import Numeric.LinearProgramming
constraints :: [Bound [Double]]
constraints =
-- first vector is valid
@timjb
timjb / PlusOne.hs
Last active September 12, 2015 10:58
{-# LANGUAGE TypeOperators, ScopedTypeVariables #-}
import Prelude hiding (until)
import Control.Monad hiding (when)
import Control.Applicative hiding (empty)
import Data.Set hiding (filter,fold, foldl,map)
import Control.FRPNow
import Control.FRPNow.Gloss
import Graphics.Gloss.Interface.Pure.Game
module BankersQueue where
data LenList a = LenList { len :: !Int, items :: [a] }
instance Monoid (LenList a) where
mempty = LenList 0 []
mappend (LenList n xs) (LenList m ys) =
LenList (n+m) (xs++ys)
coh' :: LenList a -> Maybe (a, LenList a)
coh' (LenList _ []) = Nothing
@timjb
timjb / NestedRoutesExample.hs
Created May 8, 2015 12:20
Nested routes using IsString
{-# LANGUAGE OverloadedStrings #-}
module NestedRoutesExample where
import Web.Routes.Nested
import Data.Text.Lazy as LT
import Network.Wai
import Data.Attoparsec.Text
router :: Application
@timjb
timjb / HVect.hs
Last active August 29, 2015 14:20
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RankNTypes #-}
module TraversalIso where
import Control.Lens.Traversal
import Control.Monad.State.Lazy
import Data.Traversable (Traversable (..))
{-
type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t