Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env stack
-- stack --install-ghc runghc --package sbv
import Data.Foldable
import Data.SBV
-- Encoding the Subset sum problem
-- https://en.wikipedia.org/wiki/Subset_sum_problem
subsetSum :: [SInt64] -> SInt64 -> Int -> IO SatResult
subsetSum set target subsetLength = sat $ do
#!/usr/bin/env stack
-- stack --install-ghc runghc --package sbv
import Data.SBV
main =
print =<<
(sat $
\lo m2 m1 hi ->
((lo :: SInt8) + m2 + m1 + hi .== 31)
@cheecheeo
cheecheeo / install_hlearn.sh
Created December 18, 2014 00:30
Install HLearn
#!/bin/bash -x
# % ghc --version
# The Glorious Glasgow Haskell Compilation System, version 7.6.3
cabal -j --max-backjumps -1 install hlearn-distributions-1.0.0.2 vector-heterogenous-0.1.2 ConstraintKinds-0.0.1
@cheecheeo
cheecheeo / Dockerfile
Created December 3, 2014 20:02
Dockerfile for lpaste
FROM ubuntu
RUN sudo apt-get update && sudo apt-get -y install aptitude software-properties-common git
RUN sudo aptitude -y install zlib1g-dev libcurl3-dev libpq-dev
RUN sudo add-apt-repository -y ppa:hvr/ghc && sudo aptitude update && sudo aptitude -y install cabal-install-1.20 ghc-7.8.3 happy-1.19.4 alex-3.1.3 && export PATH=/opt/alex/3.1.3/bin:/opt/happy/1.19.4/bin:$PATH && export PATH=/opt/ghc/7.8.3/bin:$PATH && cabal-1.20 update && cabal-1.20 -j -O2 install cabal-install
RUN export PATH=/opt/alex/3.1.3/bin:/opt/happy/1.19.4/bin:$PATH && export PATH=/opt/ghc/7.8.3/bin:$PATH && export PATH=$HOME/.cabal/bin:$PATH && git clone https://github.com/haskell/cabal.git && cd cabal && cd Cabal && cabal -j -O2 install && cd .. && cd cabal-install && cabal -j install -O2 && cd ..
RUN export PATH=/opt/alex/3.1.3/bin:/opt/happy/1.19.4/bin:$PATH && export PATH=/opt/ghc/7.8.3/bin:$PATH && export PATH=$HOME/.cabal/bin:$PATH && git clone https://github.com/chrisdone/lpaste.git && cd lpaste && cabal sandbox init && cabal -
@cheecheeo
cheecheeo / FoundIt.hs
Last active August 29, 2015 14:06
Finding things in a list
module FoundIt (FoundIt.elem) where
import Data.Semigroup
import Data.List.NonEmpty (NonEmpty(..))
data FoundIt a = FoundIt (a -> Bool) a
instance (Eq a) => Eq (FoundIt a) where
f1 == f2 =
case (f1, f2) of
#!/usr/bin/env bash
cabal configure && cabal build && cabal haddock --hyperlink-source \
--html-location='/package/$pkg-$version/docs' \
--contents-location='/package/$pkg'
S=$?
if [ "${S}" -eq "0" ]; then
cd "dist/doc/html"
DDIR="${1}-${2}-docs"
cp -r "${1}" "${DDIR}" && tar -c -v -z --format=ustar -f "${DDIR}.tar.gz" "${DDIR}"
CS=$?
@cheecheeo
cheecheeo / parseDate.hs
Created September 4, 2014 23:53
Heuristic Date Parsing in Haskell
module ParseDate where
import Data.Monoid
import qualified Data.Foldable as F
import Control.Newtype
import Data.Time.Calendar
import Data.Time.Clock
import Data.Time.LocalTime
import Data.Time.Format
@cheecheeo
cheecheeo / namedtuple
Created August 21, 2014 00:10
namedtuple derivatives
namedtuple is implemented an eval'd string in python, this implementation would likely copy that
```python
import geohash
Foo = initializednamedtuple('Foo', [
'lat',
'long',
('geohash', lambda self, geohash: geohash if geohash else geohash.geohash(self.lat, self.long))
])
@cheecheeo
cheecheeo / deriveShow.hs
Created July 29, 2014 00:30
One line `deriving Show` for all types in the current file
{-# LANGUAGE TemplateHaskell #-}
import Data.DeriveTH
import Data.Derive.Show
import Language.Haskell.TH.Module.Magic
newtype Foo = Foo (Int, String)
data Bar a = Bar Int | Baz a (Bar a)
foo :: Foo -> Int -> String
foo (Foo (n, s)) x = if n == x then s else ""
module ATComposeProductSum where
import Control.Applicative
import Data.Traversable
import Data.Functor.Compose
import Data.Functor.Product
import Data.Functor.Sum
import Data.Functor.Identity