Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE Arrows, TemplateHaskell #-}
module Main where
import Prelude hiding (id, init, (.))
import Control.Arrow
import Control.Category
@lspitzner
lspitzner / Djinn-env
Last active August 29, 2015 14:10
post correspondence problem in djinn env, assuming that recursive data types are allowed
-- a djinn environment that encodes an instance of the
-- post correspondence problem. it requires recursive data
-- types.
data Foo a b x y = Foo (Bar a b (a x) (b (a (a y))))
(Bar a b (a (b x)) (a (a y)))
(Bar a b (b (b (a x))) (b (b y)))
-- we need duplicate to enforce N>=1
data Bar a b x y = Bar (Bar a b (a x) (b (a (a y))))
@lspitzner
lspitzner / Main.hs
Created December 24, 2014 23:39
small example for Writer vs WriterT error message
module Main where
import Control.Monad.Trans.Writer
import Data.Monoid ( Sum(..) )
f :: Writer (Sum Int) ()
f = undefined
g :: Writer (Sum Int) Int
g = do
@lspitzner
lspitzner / cmd.sh
Created January 19, 2015 23:38
sorted list of first element of haskell module identifiers from packages on haskell
#!/bin/bash
cabal list --simple-output | sed "s/ .*//" | uniq | xargs cabal info -v | grep "^ [^ ]" | sed "s/ //" | sed "s/\..*//" | sort | uniq -c | sort -bgr
# or full module names via
#cabal list --simple-output | sed "s/ .*//" | uniq | xargs cabal info -v | grep "^ [^ ]" | sed "s/ //" | sort
# (cannot post the latter; gists seem to have length limit on what you can paste :D)
@lspitzner
lspitzner / Main.hs
Last active August 29, 2015 14:13
bad/wrong warning by ghc?
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall #-}
module Main where
data HList :: [*] -> * where
HNil :: HList '[]
@lspitzner
lspitzner / cabal-install-commands.txt
Created July 24, 2015 13:48
cabal-install common subcommands
The most common thing is to install a library (so your project can use it) or
an executable (like when you install `hoogle` so you can search documentation
locally). Behind the scenes, this involves a number of steps:
1. determine package version plan (a consistent Set (Library,Version))
2. download dependencies (i.e. their source)
3. install dependencies (i.e. do steps 1-6a for each dependency)
4. configure (think: what to build in which order, with which compiler flags etc.)
5. build
6a. register (libraries) in package repository
@lspitzner
lspitzner / output.txt
Created February 23, 2016 20:27
Cabal:test on master (a98491440b7650609bbae0e3e264e5b14a246106)
Running 2 test suites...
Test suite unit-tests: RUNNING...
Test suite unit-tests: PASS
Test suite logged to: dist/test/Cabal-1.25.0.0-unit-tests.log
Test suite package-tests: RUNNING...
package-tests: We couldn't understand the build configuration. Try editing Cabal.cabal to have 'build-type: Custom' and then rebuild
ing, or manually specifying CABAL_PACKAGETESTS_* environment variables (see README.md for more details).
Original error: Saved package config file body is corrupt. Try re-running the 'configure' command.
Test suite package-tests: FAIL
@lspitzner
lspitzner / generate-qualified-imports.sh
Last active January 19, 2018 22:41
qualified imports in stackage package sources
#!/bin/bash
ls -1 stackage | xargs -I{} bash -c "find \"stackage/{}\" -type f -name \"*.hs\" -o -name \"*.lhs\"\
| xargs grep -h \"^import\" \
| grep \" as \" \
| sed \"s/ \+as//\" \
| sed \"s/^import \+\(qualified \+\)\?//\" \
| sort \
| uniq \
" \
@lspitzner
lspitzner / nix-local-build.md
Last active July 29, 2018 23:46
nix-local-build
old-style new-style
install --only-dependencies part of new-build
install path-to-local-dir add a ./cabal.project file, add your local dependency, then use new-build (cabal.project syntax is described in the announcement)
install path-to-local-sdist does not exist yet
install remote-package-uri does not exist yet
install [--bindir=..] does not exist (yet)
configure new-configure
build (part of) new-build
clean does not exist yet; you have to remove ./dist-newstyle/ and ./cabal.project.local by hand, and potentially ./dist/ as well, i may have observed that it got touched by new-build (not sure, really). This needs to be done for each package referenced from the cabal.project as well.
@lspitzner
lspitzner / Setup.hs
Created May 25, 2016 19:21
haskell/Cabal/Setup.hs for buildnumber module auto-generation
import Distribution.Simple
import Distribution.PackageDescription
import Distribution.Simple.Program
import Distribution.Simple.Command
import Distribution.Simple.PreProcess
import Distribution.Simple.Setup
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.BuildPaths
import Distribution.Simple.BuildTarget
import System.Process