Skip to content

Instantly share code, notes, and snippets.

View paf31's full-sized avatar

Phil Freeman paf31

View GitHub Profile
@paf31
paf31 / W.lhs
Last active November 3, 2022 13:26
Algorithm W
## Principal type-schemes for functional programs
**Luis Damas and Robin Milner, POPL '82**
> module W where
> import Data.List
> import Data.Maybe
> import Data.Function
@paf31
paf31 / Tree.hs
Created June 4, 2015 06:28
Exhaustivity checking by tree coloring
module Tree where
data Binder = Wildcard | Zero | Succ Binder deriving (Show)
data Tree = Covered | Uncovered | Branch Tree Tree
color :: Tree -> Binder -> Tree
color _ Wildcard = Covered
color Covered _ = Covered
color Uncovered Zero = Branch Covered Uncovered
@paf31
paf31 / Main.hs
Last active August 29, 2015 14:22
Exhaustivity checking using prisms
module Main where
-- We will define our checker by piecing together functions based on the various types of binders.
-- We use prisms to abstract over the data constructors representing binders
type Prism a b = (a -> b, b -> Maybe a)
-- As an example, suppose we want to check array binders [_, _, ..., _] for exhaustivity.
-- We could introduce two constructors ArrNil and ArrCons, and require these constructors be
-- binders in our language.
data Array b = ArrNil | ArrCons b b deriving (Show)
@paf31
paf31 / Main.hs
Last active August 29, 2015 14:21
Category Type Class
{-# LANGUAGE FunctionalDependencies, DataKinds, GADTs, PolyKinds, KindSignatures, MultiParamTypeClasses #-}
module Main where
import Data.Monoid
import Prelude (Maybe(..))
import qualified Prelude as P
class Category (arr :: k -> k -> *) where
module Main where
import qualified Prelude as P
import Debug.Trace
class Arithmetic lang where
(+) :: lang Number -> lang Number -> lang Number
(-) :: lang Number -> lang Number -> lang Number
(*) :: lang Number -> lang Number -> lang Number
(/) :: lang Number -> lang Number -> lang Number
@paf31
paf31 / quine.purs
Created February 20, 2015 21:11
PureScript Quine
module Main where
main = Debug.Trace.trace ("module Main where\n\n" ++ code ++ "\n where code = \"\"\"" ++ code ++ "\"\"\"")
where code = """main = Debug.Trace.trace ("module Main where\n\n" ++ code ++ "\n where code = \"\"\"" ++ code ++ "\"\"\"")"""
@paf31
paf31 / memo.purs
Created December 16, 2014 01:47
Memoized functions in PureScript
module Main where
import Debug.Trace
import Data.Tuple
import Data.Either
import Data.Lazy
class Memo a where
memo :: forall r. (a -> r) -> a -> Lazy r
@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
@paf31
paf31 / 24days.md
Last active August 8, 2023 05:53
24 Days of PureScript

This blog post series has moved here.

You might also be interested in the 2016 version.

@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