Skip to content

Instantly share code, notes, and snippets.

View paf31's full-sized avatar

Phil Freeman paf31

View GitHub Profile
module Main where
import Prelude
import Parsing
import Either
foreign import data JSON :: *
foreign import toJSON "function toJSON (obj) { return obj; }" :: forall a. a -> JSON
foreign import showJSON "function showJSON (obj) { return JSON.stringify(obj); }" :: JSON -> String
@paf31
paf31 / fib.js
Created March 29, 2014 20:49
Fibonnaci sequence in PureScript
var main = function __do() {
var _4 = 1;
var _3 = 1;
return (function () {
while (_ps.Prelude.pure(_ps.Prelude.applicativeFromMonad(_ps.Control_Monad_Eff.monadEff({})))(true)()) {
(function __do() {
var _2 = _4;
var _1 = _3;
_3 = _2 + _1;
_4 = _1;
@paf31
paf31 / trampoline.purs
Last active August 29, 2015 14:01
Tramampoline!
module Main where
import Debug.Trace
data Trampoline a = Done a | More ({} -> Trampoline a)
instance functorTrampoline :: Functor Trampoline where
(<$>) f (Done a) = Done (f a)
(<$>) f (More k) = More $ \_ -> f <$> k {}
@paf31
paf31 / exists.purs
Created May 13, 2014 00:59
Existential types as a library
module Main where
foreign import data Exists :: (* -> *) -> *
foreign import mkExists
"function mkExists(fa) {\
\ return fa;\
\}" :: forall f a. f a -> Exists f
foreign import runExists
module LLC
consume : Nat -> List (Maybe Nat) -> List (Maybe Nat)
consume vid (Nothing :: vs) = Nothing :: consume vid vs
consume vid (Just v :: vs) with (vid == v)
| True = Nothing :: vs
| False = Just v :: consume vid vs
data Lolli : Type -> Type -> Type where
mkLolli : (a -> b) -> Lolli a b
@paf31
paf31 / ghcjs-purescript.hs
Created June 29, 2014 19:15
Minimal purescript front-end which compiles with GHCJS
module Main where
import qualified Language.PureScript as P
main = interact compile
where
compile text =
case P.runIndentParser "" P.parseModules "module Prelude where\nmain = \"Hello World\"" of
Left err -> show err
Right modules ->
@paf31
paf31 / code
Created August 14, 2014 17:50 — forked from emiaj/code
let isEven :: Number -> Boolean
isEven 0 = false
isEven 1 = false
isEven 2 = true
isEven n = isEven(n-1)
@paf31
paf31 / unsession.md
Last active August 29, 2015 14:06
PureScript Unsession
@paf31
paf31 / skolems.hs
Last active August 29, 2015 14:09
A new approach to the skolem escape check
module Main where
import Data.Maybe (fromMaybe)
import Control.Monad (liftM, liftM2)
data Term
= TmVar Int
| TmSkolem Int Int Int
| TmPair Term Term
@paf31
paf31 / Arbiter.hs
Last active August 29, 2015 14:11
needs a better name
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
module Main where
import Test.QuickCheck
class Arbiter f r where
arbiter :: f -> Gen r
instance Arbiter r r where