Skip to content

Instantly share code, notes, and snippets.

View hdgarrood's full-sized avatar
💭
All of my personal repos are unmaintained

Harry Garrood hdgarrood

💭
All of my personal repos are unmaintained
View GitHub Profile

Why there can be no EuclideanRing b => EuclideanRing (a -> b) instance

One of the defining features of a EuclideanRing is that you can divide any pair of elements, as long as the divisor is nonzero. Specifically, if you have a euclidean ring R, with x, y in R, and y /= zero, we need to have x = (x / y) * y + (x `mod` y).

We do have a Ring b => Ring (a -> b) instance, where multiplication is defined as follows:

@hdgarrood
hdgarrood / calc.js
Last active August 2, 2017 19:37
perf impact of reordering declaration ref list
var master = [15.985, 15.774, 16.664, 16.111, 15.889, 15.603, 15.598, 15.690, 15.602, 16.159];
var reordered = [15.831, 16.182, 16.519, 15.383, 15.936, 15.888, 15.645, 15.775, 15.749, 16.076];
function mean(arr) {
return arr.reduce(function(x,y) { return x + y; }) / arr.length;
}
function variance(arr) {
var m = mean(arr);
@hdgarrood
hdgarrood / simplex.py
Last active May 16, 2017 15:50
An extremely naive implementation of the simplex algorithm.
from collections import namedtuple
import numpy as np
# This is an implementation of the version of the simplex algorithm we are
# expected to execute by hand in LPMS. There is just one important difference:
# because python and numpy use zero-based indexing, this does too. So for
# example you need to subtract 1 from each element of your basic and nonbasic
# sets.
LPState = namedtuple("LPState", ["basic", "nonbasic"])
a9d20f4 Add test for generic deriving with awkward records (Harry Garrood, 54 seconds ago)
diff --git a/examples/passing/RecordLabels.purs b/examples/passing/RecordLabels.purs
new file mode 100644
index 0000000..b58a4bd
--- /dev/null
+++ b/examples/passing/RecordLabels.purs
@@ -0,0 +1,5 @@
+module Main where
+

Dependencies

First you'll need a docker install: https://docs.docker.com/installation/

psci

After installing Docker, we'll run a PureScript psci session by running the 0.6.1.1 image. The -it flags allocate a pseudo tty and make it interactive. We're pulling the image from the default docker hub, so the images are here and the code that builds them is on GitHub

docker run -it biscarch/purescript:0.6.1.1
module Main where
import
Prelude
Data.List (List)
Data.List as List
Control.Monad as Monad
Control.Monad.Eff.Console as Console
main = Console.log (show "hello world")
module Main where
import Prelude
import Data.Either
import Data.Functor.Compose
import Control.Monad.Eff.Console (print)
class Convert a b where
convert :: a -> b
module Main where
import Prelude
import Data.Maybe (Maybe)
import Data.List (List)
import Control.Monad.Eff.Console (print)
import Control.Comonad.Cofree (Cofree, mkCofree, head, tail)
import Control.Alternative (class Alternative)
import Control.Plus (empty)

The following packages use operator aliases and appear to have been generated with version 0.8.0 of the compiler. Since the encoding for operator aliases changed in 0.8.1, these need to be regenerated:

  • flare 0.4.3
  • flare 0.5.0
  • difflists 3.0.1-pursuit
  • difflists 3.0.1
  • neon 0.4.0
  • neon 0.4.1
  • nonempty 0.2.0
  • rationals 0.3.1
@hdgarrood
hdgarrood / Main.purs
Last active February 16, 2016 15:37
`*>` is not `flip <*`!
module Main where
import Prelude
import Data.Monoid
import Control.Apply as Apply
import Control.Monad.Writer
import Control.Monad.Eff.Console (log, print)
main = do
print (runWriter (f "hi" Apply.<* f " world"))