This file contains 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
mapVar :: (Char -> Expr a) => Expr a -> Expr a | |
mapVar f (Var d) = f d | |
mapVar _ (Const a) = Const a | |
mapVar f (a :+: b) = (mapVar f a) :+: (mapVar f b) | |
mapVar f (a :*: b) = (mapVar f a) :*: (mapVar f b) | |
mapVar f (a :^: b) = (mapVar f a) :^: (mapVar f b) | |
mapVar f (a :/: b) = (mapVar f a) :/: (mapVar f b) | |
plugIn :: Char -> a -> Expr a -> Expr a | |
plugIn c val = mapVar (\x -> if x == c then Const val else Var x) |
This file contains 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 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 |
This file contains 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 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 |
This file contains 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
map ($ 1000) [(+10), (*800), (/300)] | |
-- [1010.0,800000.0,3.3333333333333335] | |
foldr ($) 8 [(+5), (*2)] | |
-- 21 | |
-- (8 * 2 + 5) |
This file contains 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 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 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 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 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 |
This file contains 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 ++ ")" |