Skip to content

Instantly share code, notes, and snippets.

addColor :: forall (c :: Symbol) t. KnownSymbol c => SomeColor -> ThemeInstance t -> ThemeInstance (c : t)
addColor sc (ThemeInstance m) = ThemeInstance $ Map.insert colorName sc m
where colorName = symbolVal (Proxy @c)
emptyThemeInstance :: ThemeInstance '[]
emptyThemeInstance = ThemeInstance Map.empty
@paraseba
paraseba / performance.hs
Created June 20, 2018 16:32
Uncommenting the type signature produces slower code
import qualified Data.Vector.Generic.Mutable as MV
--mutableEval :: MV.MVector v Int8 => [Op] -> v RealWorld Int8 -> Int -> IO Int
mutableEval [] _ pos = return pos
mutableEval (op:ops) mem pos = case op of
Inc n memOffset ->
(MV.unsafeModify mem (+ fromIntegral n) (pos + coerce memOffset) >> mutableEval ops mem pos)
MRight n -> mutableEval ops mem (pos + coerce n)
@paraseba
paraseba / scopedLens.hs
Last active June 3, 2018 23:21
How to refer to a type variable hidden under an alias?
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ScopedTypeVariables #-}
type Lens s t a b =
forall f.
Functor f =>
(a -> f b)
-> s
-> f t
@paraseba
paraseba / folds.scala
Created May 30, 2018 14:04
Demonstration of implementing foldRight with by-name parameter
/*
This is a demonstration of foldLeft and foldRight in scala using
by-name parameters to process infinite streams and to short-circuit
computations that can finish early.
*/
import scala.annotation.tailrec
/*
foldLeft can be written in tail recursive form. The recursive call is not
[latexmath]
++++
f(p) \leq q \iff p \leq g(q)
++++

Conway’s law, as misused as CAP

You know how the CAP theorem is frequently misunderstood and abused to justify any random design space decision in distributed systems? Of course you do, there is so much written about it. Well there is another, much easier to understand, much weaker but equally abused “result” [1], Conway’s law.

Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the

Keybase proof

I hereby claim:

  • I am paraseba on github.
  • I am paraseba (https://keybase.io/paraseba) on keybase.
  • I have a public key whose fingerprint is F634 BC3E 4DF3 CBF1 35F7 0158 9067 9A7E 1C48 CC35

To claim this, I am signing this object:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512,SHA1
I am transitioning GPG keys from an old 1024 and 2048-bit key to a new
4096-bit RSA key.
This transition document is signed with the 3 keys to validate the
transition.
The old keys, which I am transitional away from, is:
<html>
<body><p>hello world</p></body></html>

Keybase proof

I hereby claim:

  • I am paraseba on github.
  • I am paraseba (https://keybase.io/paraseba) on keybase.
  • I have a public key whose fingerprint is 9D6D 0755 86C2 1B61 42D1 7883 8124 48E5 924F EEA5

To claim this, I am signing this object: