Skip to content

Instantly share code, notes, and snippets.

View paf31's full-sized avatar

Phil Freeman paf31

View GitHub Profile
@paf31
paf31 / DKT.hs
Last active April 30, 2021 06:59
Statically-typed values with dynamically-kinded types
{-# language FlexibleContexts #-}
{-# language TypeOperators #-}
module DKT where
import Control.Monad (guard)
import Control.Monad.Error.Class (throwError)
import Control.Monad.Trans (lift)
import Control.Monad.Trans.State
import Control.Monad.Trans.Writer
@paf31
paf31 / ToPursTyConPoly.hs
Last active April 8, 2020 07:08
ToPursTyConPoly
{-# language TypeInType #-}
-- | Types which have PureScript equivalents
class ToPursTyCon a where
toPursTyCon :: Tagged a PursTypeConstructor
-- | The default instance uses 'G.Generic' and pattern matches on the
-- type's representation to create a PureScript type.
default toPursTyCon :: (G.Generic a, GenericToPursTyCon (G.Rep a)) => Tagged a PursTypeConstructor
toPursTyCon = retag $ genericToPursTyConWith @(G.Rep a) defaultPursTypeOptions
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 / 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 / FreeAp.md
Last active September 17, 2019 21:08
FreeAp f is a Comonad

FreeAp f is a Comonad

While thinking about comonads as spaces and Day convolution, I realized an interesting thing. The free applicative functor generated by a comonad f is also a comonad.

The free applicative can be defined in a few different ways, but I like to define it like this:

data FreeApplicative f a = Pure a | Free (Day f (FreeApplicative f) a)
@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)
@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.hs
Last active September 5, 2018 03:54
A simple type checker with Rank N types
module Main where
import Data.Maybe (fromMaybe)
import Control.Applicative
import Control.Arrow (first)
import Control.Monad (ap)
import Debug.Trace
@paf31
paf31 / ListT.purs
Created August 27, 2015 04:03
Stack-safe ListT in PureScript using FreeT
module Control.Monad.List.Trans where
import Prelude
import Data.List
import Data.Either
import Control.Apply
import Control.Bind
import Control.Monad.Eff
@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