Skip to content

Instantly share code, notes, and snippets.

View tkersey's full-sized avatar
:octocat:

Tim Kersey tkersey

:octocat:
View GitHub Profile
@tkersey
tkersey / CoC.ml
Created February 25, 2023 22:50 — forked from hirrolot/CoC.ml
How to implement dependent types in 80 lines of code
type term =
| Lam of (term -> term)
| Pi of term * (term -> term)
| Appl of term * term
| Ann of term * term
| FreeVar of int
| Star
| Box
let unfurl lvl f = f (FreeVar lvl)
@tkersey
tkersey / youtube.md
Created January 28, 2023 19:15 — forked from bitsurgeon/youtube.md
Markdown cheatsheet for YouTube

Embed YouTube Video in Markdown File

  1. Markdown style
[![Watch the video](https://img.youtube.com/vi/nTQUwghvy5Q/default.jpg)](https://youtu.be/nTQUwghvy5Q)
  1. HTML style
<a href="http://www.youtube.com/watch?feature=player_embedded&v=nTQUwghvy5Q" target="_blank">
@tkersey
tkersey / HowTo use xcconfig or plist with SPM.md
Created November 30, 2022 15:39 — forked from 4np/HowTo use xcconfig or plist with SPM.md
How to use a .xcconfig file and a .plist with a Swift Package Manager based project.

How to use a .xcconfig file and a .plist file with SPM

Worth a read for some more context.

Create a Package.xcconfig file

Create the file in the root of the project (where your Package.swift file lives as well), and use the following contents:

/// Package.xcconfig
@tkersey
tkersey / Combinators.swift
Created November 28, 2022 15:41 — forked from danielt1263/Combinators.swift
A list of combinators
func apply<A, B>(fn: (A) -> B, a: A) -> B {
fn(a)
}
func bluebird<A, B, C>(fn1: (A) -> B, fn2: (C) -> A, c: C) -> B {
fn1(fn2(c))
}
func blackbird<A, B, C, D>(fn1: (C) -> D, fn2: (A, B) -> C, a: A, b: B) -> D {
@tkersey
tkersey / xcode-vim.markdown
Created November 16, 2022 16:40 — forked from gdavis/xcode-vim.markdown
Notes for working with Xcode VIM mode

Xcode VIM

This document is a scratchpad for helping me learn commonly used actions in Xcode's VIM mode.

Commands are case-sensitive. A command of N means pressing shift + n on the keyboard.

[Formatting is a WIP]


Normal Mode Commands

Basic Navigation

@tkersey
tkersey / Moore.hs
Created March 6, 2022 23:31 — forked from ekmett/Moore.hs
Moore for Less
{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
import Control.Applicative
import Control.Comonad
import Data.Bifunctor
@tkersey
tkersey / alltheflags.md
Created November 29, 2021 19:05 — forked from CodaFi/alltheflags.md
Every Option and Flag /swift (1.2) Accepts Ever

#Every Single Option Under The Sun

  • optimization level options
  • automatic crashing options
  • debug info options
  • swift internal options
  • swift debug/development internal options
  • linker-specific options
  • mode options
@tkersey
tkersey / Continuations.swift
Created November 29, 2021 18:46 — forked from CodaFi/Continuations.swift
A Swift Continuation Monad
// Playground - noun: a place where people can play
public func id<A>(x : A) -> A {
return x
}
public func error<A>(x : String) -> A {
assert(false, x)
}
@tkersey
tkersey / Y.swift
Created November 29, 2021 18:19 — forked from CodaFi/Y.swift
The Y Combinator in Swift
public func unsafeCoerce<A, B>(_ x : A) -> B {
return unsafeBitCast(x, to: B.self)
}
func Y<A>(_ f : @escaping (A) -> A) -> A {
return { (x : @escaping (A) -> A) in
return f((x(unsafeCoerce(x))))
}({ (x : A) -> A in
let fn : (A) -> A = unsafeCoerce(x)
return f(fn(x))

Copy and paste the swift code below into a playground to experiment.

This is a very close emulation of Functor and Monad typeclasses in swift. As of Swift 1.2 and Xcode 6.3, this is no longer very fragile.

Unfortunately, the compiler cannot verify the types when passing a function to (>>=). We have to wrap the function in a closure and call it with an explicit argument to compile.

optionalDoubles >>= squareRoot // doesn't compile
optionalDoubles >>= { squareRoot($0) } // compiles