Skip to content

Instantly share code, notes, and snippets.

View Kazark's full-sized avatar

Keith Pinson Kazark

  • Undisclosed
View GitHub Profile
@ChristopherDavenport
ChristopherDavenport / SetOnceCache.scala
Last active October 11, 2021 13:06
Set Once Cache
import cats._
import cats.implicits._
import cats.effect._
import cats.effect.implicits._
import scala.concurrent.duration._
import io.chrisdavenport.mapref._
trait SetOnceCache[F[_], K, V]{
def get(k: K): F[V]
@ChristopherDavenport
ChristopherDavenport / CaseClassFun.scala
Last active December 10, 2020 22:13
Generic Show Derivation of Case Classes using Scala 3
package io.chrisdavenport.shapelessless
import cats._
import cats.syntax.all._
import cats.effect._
import scala.deriving._
import scala.compiletime._
import org.tpolecat.typename._
@minad
minad / polyp.md
Last active February 9, 2024 10:51
Polyp: Small child of the Hydra

Polyp: Small child of the Hydra

;; The undo keybindings `C-x u` and `C-_` enter the polyp.
(defpolyp polyp-undo
  "_u_ndo  _r_edo"
  ("u" undo-fu-only-undo "C-x u" "C-_")
  ("r" undo-fu-only-redo))
@alphapapa
alphapapa / emacs-27-svg-screenshot.svg
Last active August 22, 2020 15:53
Emacs 27 can take SVG screenshots of itself
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@amohrland
amohrland / Naturals.agda
Created July 14, 2020 19:22
Naturals.agda
module plfa.part1.Naturals where
data N : Set where
zero : N
suc : N -> N
{-# BUILTIN NATURAL N #-}
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
@ChristopherDavenport
ChristopherDavenport / build.sbt
Created June 15, 2020 15:40
Basic Packaging For SBT Projects - Underscores in filenames indicate directories
scalaVersion := "2.13.1"
enablePlugins(JavaAppPackaging)
maintainer := "foo@blah.com"
dockerBaseImage := "java:14"

Monads and delimited control are very closely related, so it isn’t too hard to understand them in terms of one another. From a monadic point of view, the big idea is that if you have the computation m >>= f, then f is m’s continuation. It’s the function that is called with m’s result to continue execution after m returns.

If you have a long chain of binds, the continuation is just the composition of all of them. So, for example, if you have

m >>= f >>= g >>= h

then the continuation of m is f >=> g >=> h. Likewise, the continuation of m >>= f is g >=> h.

@chrisdone
chrisdone / Intro.md
Last active April 10, 2023 06:33
Statically checked overloaded strings

Statically checked overloaded strings

This gist demonstrates a trick I came up with which is defining IsString for Q (TExp a), where a is lift-able. This allows you to write $$("...") and have the string parsed at compile-time.

On GHC 9, you are able to write $$"..." instead.

This offers a light-weight way to enforce compile-time constraints. It's basically OverloadedStrings with static checks. The inferred return type

@emcake
emcake / applicative-builders.fs
Last active February 15, 2021 15:10
Applicative builders in F# by abusing For and IsLikeZip
type ListBuilder() =
/// map
member x.For(l,f) =
List.map f l
/// id
member x.Yield(v) =
v
;; The next line may not be needed
(set-default-font "Source Code Pro for Powerline 13")
;; Fira code
;; This works when using emacs --daemon + emacsclient
(add-hook 'after-make-frame-functions (lambda (frame) (set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")))
;; This works when using emacs without server/client
(set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")
;; I haven't found one statement that makes both of the above situations work, so I use both for now