This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Control.Monad.State | |
import Data.Text | |
import Data.Monoid | |
import qualified Data.Map as M | |
import Control.Monad |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Pipes | |
import qualified Pipes.Prelude as P | |
import qualified System.Random as R | |
import Lens.Family2 | |
import Lens.Family2.Stock | |
import Lens.Family2.State.Lazy | |
import Control.Monad.Trans.State | |
import Control.Monad | |
import Control.Concurrent(threadDelay) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = mapM_ printNotExpr . lines =<< readFile "inputs.txt" | |
where printNotExpr e = case parseExpr e of | |
Right x -> print $ not x | |
Left e -> error $ show e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance Show Expr where | |
show (Not e) = "NOT " ++ show e | |
show (And e1 e2) = show e1 ++ " AND " ++ show e2 | |
show (Or e1 e2) = show e1 ++ " OR " ++ show e2 | |
show (Var c) = [c] | |
show (SubExpr e) = "(" ++ show e ++ ")" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parseExpr :: String -> Either ParseError Expr | |
parseExpr = parse expr "" | |
where expr = buildExpressionParser operators term <?> "compound expression" | |
term = parens expr <|> variable <?> "full expression" | |
operators = [ [Prefix (string "NOT" *> spaces *> pure Not)] | |
, [binary "AND" And] | |
, [binary "OR" Or] ] | |
where binary n c = Infix (string n *> spaces *> pure c) AssocLeft | |
variable = Var <$> (letter <* spaces) <?> "variable" | |
parens p = SubExpr <$> (char '(' *> spaces *> p <* char ')' <* spaces) <?> "parens" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
not :: Expr -> Expr | |
not (Not e) = e | |
not (And e1 e2) = Or (not e1) (not e2) | |
not (Or e1 e2) = And (not e1) (not e2) | |
not (SubExpr e) = not e | |
not (Var c) = Not (Var c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Expr = Not Expr | |
| And Expr Expr | |
| Or Expr Expr | |
| SubExpr Expr | |
| Var Char | |
deriving Eq |