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
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)
{-# LANGUAGE DataKinds, GADTs, MultiParamTypeClasses, PolyKinds, TypeOperators, FlexibleInstances, TypeFamilies, UndecidableInstances #-}
import GHC.TypeLits
module Knockout where
data PrimType = String | Number
data Model
= ObsPrim { primType :: PrimType }
@paf31
paf31 / Juggling.elm
Last active December 17, 2015 16:29
Juggling in Elm
pauseTime = 0.35
timePerThrow = 300
handMovement = 0.2
pattern = [5]
rotatePattern : Int -> [a] -> [a]
rotatePattern n xs =
@paf31
paf31 / markup.hs
Last active December 17, 2015 07:28
A small typed markup language based on Haskell syntax
{-# LANGUAGE FlexibleContexts #-}
module Markup where
import Text.Parsec
import qualified Text.Parsec.Token as P
import qualified Text.Parsec.Language as L
import qualified Text.Parsec.Expr as E
import Data.Char
import Data.List (groupBy, nub, (\\))
@paf31
paf31 / parse_nested.hs
Last active December 17, 2015 03:18
A Parsec parser which only recognizes balanced binary trees.
import Text.Parsec
data Tree a = Tip a | Branch (Tree (a, a)) deriving (Show)
tree :: Parsec String u (Tree Int)
tree = tree' $ do
ds <- many digit
return $ read ds
where
tree' :: Parsec String u a -> Parsec String u (Tree a)
@paf31
paf31 / Total.hs
Created April 26, 2013 20:47
Total language, work in progress
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}