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 Data.Exists (Exists, mkExists, runExists)
import Unsafe.Coerce (unsafeCoerce)
-- Leibniz equality:
-- Two things are equal if they are substitutable in all contexts.
type Leib a b = forall f. f a -> f b
@paf31
paf31 / traverse.purs
Created November 24, 2015 19:16
Profunctor-based Traversable
module Main where
import Prelude
import Data.Maybe
import Data.Either
import Data.Tuple
import Data.List
import Data.Profunctor
@paf31
paf31 / Main.purs
Last active February 2, 2018 23:28
Try Behaviors
module Main where
import Prelude
import Color (white)
import Color.Scheme.MaterialDesign (blueGrey)
import Control.Monad.Eff (Eff)
import Control.MonadZero (guard)
import Data.Array (sortBy, (..))
import Data.Foldable (foldMap)
@paf31
paf31 / Deriv.idr
Last active July 20, 2017 07:14
Calculus of types in idris
module Deriv
import Control.Isomorphism
--
-- A type constructor df is the derivative of the type constructor f if for all x and e there exists d such
-- such that
--
-- f (x + e) ~ f x + e * (df x) + e^2 * d
--
@paf31
paf31 / .psci
Last active December 15, 2016 13:08
Minimal .psci file for 0.7
:f bower_components/purescript-prelude/src/Prelude.js
:m bower_components/purescript-prelude/src/Prelude.purs
:f bower_components/purescript-eff/src/Control/Monad/Eff.js
:m bower_components/purescript-eff/src/Control/Monad/Eff.purs
:f bower_components/purescript-console/src/Control/Monad/Eff/Console.js
:m bower_components/purescript-console/src/Control/Monad/Eff/Console.purs
:f bower_components/purescript-eff/src/Control/Monad/Eff/Unsafe.js
:m bower_components/purescript-eff/src/Control/Monad/Eff/Unsafe.purs
import Prelude
import Control.Monad.Eff.Console
@paf31
paf31 / gist:e3feef9eb85c7ce9ce0a5e0db7441059
Last active December 10, 2016 00:21
PureScript projects needing ownership
## Current owners
- Typechecker (Phil)
- Modules (Gary)
- Corefn optimization and codegen (Gary)
- Core libraries (Gary)
- IDE integration (Christoph)
- Pursuit (Harry)
- PSCi (Phil)
- Docs repo (Harry)
data Zero = Zero
data Succ a = Succ a
pred = \s -> case s of Succ a -> a
meters = \n ->
{ multiply: \v -> v { value = n * v.value, meters = Succ (v.meters) }
, divide: \v -> v { value = n / v.value, meters = pred (v.meters) }
}
@paf31
paf31 / units.ps
Last active December 29, 2015 14:49
data Zero = Zero
data Succ a = Succ a
pred = \s -> case s of Succ a -> a
meters = \n v -> v { value = n * v.value, meters = Succ (v.meters) }
seconds = \n v -> v { value = n * v.value, seconds = Succ (v.seconds) }
@paf31
paf31 / quineo.hs
Last active December 27, 2015 23:48
Not working yet
{-# LANGUAGE PolymorphicComponents, GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
import Data.Data
import Data.Maybe
import Data.Generics
import Data.Monoid
import Control.Applicative
import Control.Monad.State
import Control.Monad.Logic
import Control.Monad.Logic.Class
@paf31
paf31 / Patterns.hs
Last active December 22, 2015 14:58
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Applicative (Applicative(..), Alternative(..))
import Data.Function (fix)
import qualified Control.Category as C
import Control.Category ((>>>))
import qualified Control.Arrow as A
import Control.Arrow ((***))
newtype Pattern a b = Pattern { runPattern :: A.Kleisli Maybe a b } deriving (C.Category, A.Arrow)