Skip to content

Instantly share code, notes, and snippets.

View tonymorris's full-sized avatar

Tony Morris tonymorris

View GitHub Profile
@tonymorris
tonymorris / main.hs
Created July 2, 2021 06:54 — forked from gregberns/main.hs
How to make a Foldable Instance with multiple parameters
import Data.Monoid
-- This code doesn't work...
-- How can you make a multi-parameter data type be Foldable?
-- foldMap over `a` so it can be converted to a Monoid
data BinaryTree3 a v
= Node3 a (BinaryTree3 a v) (BinaryTree3 a v)
| Leaf3 a v
deriving (Show)
@tonymorris
tonymorris / Optics Cheatsheet.md
Last active June 1, 2020 10:40 — forked from ChrisPenner/Optics Cheatsheet.md
Optics Cheatsheet

Our web applications are getting increasingly more complicated. They are becoming more distributed and increasingly powered by combinations of complex, constantly changing and large datasets. All while users are increasingly more connected and want the latest information instantly without any slow page loads or stale information.

To address this, developers have turned to layers of caching and single page applications so that there are layers of aggregated and preloaded state as close to the user as possible, to be immediately available when it is requested. This comes at a high cost: it is very difficult to invalidate or update those caches when the upstream information changes. This is especially problematic when the stale caches can accidentally cause real bugs rather than show stale data to users.

The big issue here is that we're not just caching expensive-to-compute static data. We are caching data that changes over time. There are a number of architectual patterns that can be applied, but to date, n

  • mount indicators
  • install air filter
  • install rear rack
  • install braided fuel line
  • install headlight protector
  • mount spotlights
  • install windscreen
  • change oil filters
  • install foam air filter
  • adjust rear shock
Response to https://peerj.com/preprints/826v1/
1.
The method is dubious with respect to the conclusion.
The researchers do not analyse the code using any formal
or even established reliable methods. Instead, the metric that is used is "look
to see if some *detected* bug, which was fixed *post-release*.

Parametricity, or Theorems for Free

Say more by saying less. Learn how parametric types, when used in conjunction with an adequately strong type system, help the programmer comprehend code by invalidating candidate programs. Parametricity helps the programmer by enabling deduction of theories about what a program cannot do, sometimes to the point of leaving no ambiguity.

import System.Environment
import System.IO
import Control.Monad (when)
matchGlob :: String -> String -> Bool
matchGlob = undefined
main :: IO ()
main = do
args <- getArgs
@tonymorris
tonymorris / everyN.hs
Last active August 29, 2015 13:58 — forked from anonymous/everyN.hs
module Every where
import Control.Lens
import Control.Monad.Fix
-- |
--
-- >>> everyN 2 []
-- []
--
hardCoreFunction a b c =
let z = a + b
k = b + c
in
error "todo" z + k -- this obviously type-checks
object blah {
case class OptionT[F[_], A](x: F[Option[A]])
trait Functor[F[_]]
object Functor {
implicit val OptionFunctor: Functor[Option] =
sys.error("todo")
}
object OptionT {
implicit def OptionTFunctor[F[_]: Functor]: Functor[({ type l[a] = OptionT[F, a] })#l] =