Skip to content

Instantly share code, notes, and snippets.

View evincarofautumn's full-sized avatar

Jon Purdy evincarofautumn

View GitHub Profile
@evincarofautumn
evincarofautumn / ComposeDo.hs
Created November 1, 2017 00:30
Compositional do notation
{-# LANGUAGE RebindableSyntax #-}
import Control.Arrow
import Control.Monad
import Data.Function
import Data.Monoid
import Prelude
import System.IO
main :: IO ()
@evincarofautumn
evincarofautumn / oop.funk
Created August 23, 2017 23:10
OOP experiments in Funk
if := {
|True t _| t()
|False _ e| e()
}
point := {|x y| {
; Multiple constants in a pattern are a parse error. I’d like to write:
; |Has X| True
; |Has Y| True
@evincarofautumn
evincarofautumn / BeepBoop.hs
Last active August 2, 2017 17:56
Using GADTs with Free (with fewer typeclasses & extensions)
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
module Main where
import Control.Monad (forM_, join)
import Control.Monad.Free (Free(..), liftF)
import System.Random (randomRIO)
data Hide g r where
@evincarofautumn
evincarofautumn / BeepBoop.hs
Last active August 2, 2017 11:03
Using GADTs with Free
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Main where
import Control.Monad (forM_, join)
import Control.Monad.Free (Free(..), liftF)
@evincarofautumn
evincarofautumn / table-notation.txt
Created June 26, 2017 21:43
Kitten table notation
1 10 range \even filter \(^ 2) map \say each
+---+----+----------+-----------+---------+
| 1 | 10 | +------+ | +-------+ | +-----+ |
+---+----+ | even | | | _ ^ 2 | | | say | |
| range | +------+ | +-------+ | +-----+ |
+--------+----------+ | |
| filter | | |
+-------------------+-----------+ |
| map | |
@evincarofautumn
evincarofautumn / CMonad.hs
Created June 10, 2017 19:09
Constrained monads with multi-parameter typeclasses
{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses #-}
import Data.Set (Set)
import qualified Data.Set as Set
class Unit m a where
unit :: a -> m a
class (Unit m a, Unit m b) => Bind m a b where
bind :: m a -> (a -> m b) -> m b
@evincarofautumn
evincarofautumn / Random.hs
Last active May 18, 2017 00:11
Arbitrary-like API for randomness
import Control.Monad
import System.Random
class Roll k r where
roll :: k -> IO r
instance Roll Int Int where
roll = pure
instance (Roll k r, Random a, Integral a) => Roll (a -> k) r where
$ ls
Makefile
$ make me a sandwich
What? Make it yourself.
$ ls
Makefile
$ sudo make me a sandwich
Okay.
$ ls
@evincarofautumn
evincarofautumn / constraints.ktn
Last active February 10, 2017 02:24
Trait constraints and assumptions in Kitten
// A constraint could be sugar for a permission:
//
// “where (foo<T>)” → “+Defined(foo<T>)”
// “where (<A, B> map<F<_>, A, B>)” → “+Defined(<A, B> map<F<_>, A, B>)”
//
// It looks like effects and coeffects can both be represented with permissions because all terms are functions.
trait (<)<T> (T, T -> Bool)
trait zero<T> (-> T)
trait neg<T> (T -> T)
@evincarofautumn
evincarofautumn / lens.ktn
Last active February 8, 2017 10:27
Translating the lens tutorial to Kitten
// data Atom = Atom { _element :: String, _point :: Point }
type Atom:
case mkatom:
_element as (Text)
_point as (Point)
// data Point = Point { _x :: Double, _y :: Double }
type Point:
case mkpoint:
_x as (Float64)