Skip to content

Instantly share code, notes, and snippets.

@erantapaa
erantapaa / Misc.hs
Created June 1, 2016 07:01
withOutputTo
module Misc
( withOutputTo
) where
import System.IO
import GHC.IO.Handle
import Control.Exception
-- | Run an IO action with stdout redirected to a file.
-- Restores stdout upon completion of the action.
@erantapaa
erantapaa / perms.hs
Last active May 27, 2016 10:51
experiments with permutations in Haskell
{-# LANGUAGE NoMonomorphismRestriction #-}
-- Experiments with permutations
import Data.List
-- import qualified Math.Algebra.Group.PermutationGroup as PG
-- number of inversions in a permutation
inversions as = sum $ map go (tails as)
where go [] = 0
@erantapaa
erantapaa / 1had-fetch.py
Created May 26, 2016 12:02
1had-fetch.py - recursively fetch 1had modules from paste
#!/usr/bin/env python
#
# A script to recursively fetch 1haskelladay modules from lpaste
import re
import os
import requests
import codecs
import sys
@erantapaa
erantapaa / Lib.hs
Created May 22, 2016 23:34
some Yesod / Persistent examples
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
@erantapaa
erantapaa / parts.py
Created November 18, 2015 16:28
generating partitions
# Generator for partitions of an integer.
#
# See http://jeromekelleher.net/category/combinatorics.html
def ruleAsc(n):
a = [0 for i in range(n + 1)]
k = 1
a[1] = n
while k != 0:
x = a[k - 1] + 1
@erantapaa
erantapaa / Lib.hs
Last active November 16, 2015 04:00
Pipes.Aeson examples
{-# LANGUAGE OverloadedStrings, DeriveGeneric, NoMonomorphismRestriction, RankNTypes, BangPatterns #-}
-- build-depends: base >= 4.7 && < 5, bytestring, pipes-aeson, pipes-parse, pipes, aeson, vector, text
-- This file contains examples of how to use functions in Pipes.Aeson.
module Lib
where
import GHC.Generics
@erantapaa
erantapaa / a-concurrent-process-example.hs
Created November 11, 2015 15:40
Example of concurrently processing output form a process.
-- from the School of Haskell article: https://www.fpcomplete.com/user/snoyberg/library-documentation/data-conduit-process
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative ((*>))
import Control.Concurrent.Async (Concurrently (..))
import Data.Conduit (await, yield, ($$), (=$))
import qualified Data.Conduit.Binary as CB
import qualified Data.Conduit.List as CL
import Data.Conduit.Process (ClosedStream (..), streamingProcess,
@erantapaa
erantapaa / Foo.hs
Created November 2, 2015 23:03
Template Haskell examples
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
module Foo where
import MyTH
foo x = x + 1
$(describe "dfoo" 'foo) -- defines the function "dfoo"
@erantapaa
erantapaa / README-NEW.md
Last active October 26, 2015 03:55
build a Dash docset for the GHC API

Instructions for building a Dash docset for the GHC API (for ghc 7.10.2)

The ghc module is hidden by default, so it's not included in any of the Haskell docsets I could find. Here is a recipe for building a docset which contains just ghc-7.10.2.

Step 1. Build https://github.com/erantapaa/haddocset

Step 2. Find the location of the ghc package conf file. If you have installed the Haskell Platform it will reside at:

@erantapaa
erantapaa / README.md
Last active October 26, 2015 02:16
build a Dash docset for the GHC API

Instructions for building a Dash docset for the GHC API (for ghc 7.10.2)

The ghc module is hidden by default, so it's not included in any of the Haskell docsets I could find. Here is a recipe for building a docset which contains just ghc-7.10.2.

  1. Build https://github.com/philopon/haddocset
  2. In a work directory, copy the null-ghc-pkg script
  3. Make the null-ghc-pkg script executable