Skip to content

Instantly share code, notes, and snippets.

@5outh
5outh / docgen.sh
Last active August 29, 2015 14:04
Manual hackage documentation upload
# Usage (from project root): ./docgen.sh <Repo Name> <Version> <Hackage Username> <Hackage Password>
# e.g. ./docgen.sh Bang 0.1.1.0 5outh F4kePa55word
#!/bin/bash
cabal configure && cabal build && cabal haddock --hyperlink-source \
--html-location='http://hackage.haskell.org/package/$pkg/docs' \
--contents-location='http://hackage.haskell.org/package/$pkg'
S=$?
if [ "${S}" -eq "0" ]; then
cd "dist/doc/html"
DDIR="${1}-${2}-docs"
# Note: This is after the lines restricting php 7 have been commented out in `configure`. My PHP Version output:
$ php --version
PHP 7.0.5 (cli) (built: Mar 31 2016 06:38:23) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
$ export LIBFFI_PATH=$(brew --prefix libffi)
$ LDFLAGS=" -L${LIBFFI_PATH}/lib" PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${LIBFFI_PATH}/lib/pkgconfig" ./configure
./configure: line 624: test: /Applications/Sublime: binary operator expected
-- For example
type JSON = Text
-- An instance of RenderResponse knows how to turn itself into JSON
class RenderResponse a where
render :: a -> JSON
data Error = Error Text
data RegularResponse = RegularResponse Text -- For example
data ErrorResponse a = ErrorResponse a [Error] -- Parameterize over Response type
@5outh
5outh / events.hs
Created May 3, 2016 22:14
Event System in Haskell
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.State
import Data.Text
import Data.Monoid
import qualified Data.Map as M
import Control.Monad
map ($ 1000) [(+10), (*800), (/300)]
-- [1010.0,800000.0,3.3333333333333335]
foldr ($) 8 [(+5), (*2)]
-- 21
-- (8 * 2 + 5)
data Rational : Nat -> Nat -> Type where
MkRational : (a : Nat) -> (b : Nat) -> Rational a b
MultRat : Rational a b -> Rational c d -> Rational (a*c) (b*d)
DivRat : Rational a b -> Rational c d -> Rational (a*d) (b*c)
AddRat : Rational a b -> Rational c d -> Rational (a*d + b*c) (b*d)
Simplify : Rational a b -> Rational (divNat a (gcd a b)) (divNat b (gcd a b))
||| λΠ> :t Simplify (DivRat (MkRational 770 30) (MkRational 3 4))
||| Simplify (DivRat (MkRational 770 30) (MkRational 3 4)) : Rational 308 9
@5outh
5outh / natstyle.hs
Created October 17, 2016 16:21
Style proposal
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module Main where
import Control.Monad.Morph
import Control.Monad.Reader hiding (reader)
import Control.Monad.State hiding (state)
import Control.Monad.Except
import Control.Monad.IO.Class
@5outh
5outh / postgresql-simple.hs
Created February 9, 2017 01:40
postgresql-simple
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad.State
import Control.Monad.Reader
import Data.Text
import Database.PostgreSQL.Simple
import Database.PostgreSQL.Simple.FromRow
import Database.PostgreSQL.Simple.ToRow
import Data.Maybe (fromJust)
@5outh
5outh / mysql-simple.hs
Created February 11, 2017 14:07
mysql-simple example
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
module Main where
import Control.Monad.State
import Control.Monad.Reader
import Data.Text
import Database.MySQL.Simple
@5outh
5outh / persistent-postgresql.hs
Created February 13, 2017 01:16
persistent-postgresq example
{-# LANGUAGE OverloadedStrings #-}
import Types
import Database.Persist.Postgresql
import Control.Monad.Logger
import Control.Monad.IO.Class
printIO :: (MonadIO m, Show a) => a -> m ()
printIO = liftIO . print