Skip to content

Instantly share code, notes, and snippets.

View tkersey's full-sized avatar
👹

Tim Kersey tkersey

👹
View GitHub Profile
@paf31
paf31 / DKT.hs
Last active April 30, 2021 06:59
Statically-typed values with dynamically-kinded types
{-# language FlexibleContexts #-}
{-# language TypeOperators #-}
module DKT where
import Control.Monad (guard)
import Control.Monad.Error.Class (throwError)
import Control.Monad.Trans (lift)
import Control.Monad.Trans.State
import Control.Monad.Trans.Writer
@julesjans
julesjans / screen-gif.sh
Last active May 8, 2021 16:40
Capture iOS Simulator to animated gif
# Turn on the simulator screen capture
xcrun simctl io booted recordVideo ~/simulator.mov
# Convert the iPhone 6s screen shot into a gif:
ffmpeg -i ~/simulator.mov -vf scale=320:-1 -r 6 -f gif -y simulator.gif
@brennanMKE
brennanMKE / Playground.swift
Last active May 11, 2021 18:37
Path Reader for Dictionaries and Arrays as well as Info.plist
import Foundation
typealias AnyDictionary = [String: Any]
typealias AnyArray = [Any]
enum PathSeparator {
case character(Character)
case custom((String) -> [String])
func separate(path: String) -> [String] {
//: A Cocoa based Playground to present user interface
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
HStack {
VStack {
HStack {
@ekmett
ekmett / IndicesAndLevels.hs
Last active August 4, 2021 18:27
a pragmatic mix of de bruijn indices and levels
{-# language PolyKinds #-}
{-# language BlockArguments #-}
{-# language AllowAmbiguousTypes #-}
{-# language StrictData #-}
{-# language DerivingStrategies #-}
{-# language GeneralizedNewtypeDeriving #-}
{-# language TypeApplications #-}
{-# language BangPatterns #-}
{-# language NPlusKPatterns #-}
{-# language TypeFamilies #-}
@dabrahams
dabrahams / Example1.swift
Last active August 4, 2021 18:28
Ambiguity problems with giving generic types the right behavior with conditional conformances
protocol P { var pop: String { get } }
extension P {
var pop: String { "slow" }
var pop1: String { pop }
}
protocol Q: P {}
extension Q { var pop: String { "fastQ" } }
protocol R: P {}
@lukeredpath
lukeredpath / Validations.swift
Last active October 16, 2021 17:57
A little experiment with functional Rails-style validators built on top of pointfreeco/Validated
import UIKit
import Validated
extension Validated {
func mapErrors<LocalError>(_ transform: (Error) -> LocalError) -> Validated<Value, LocalError> {
switch self {
case let .valid(value):
return .valid(value)
case let .invalid(errors):
return .invalid(errors.map(transform))
@tkersey
tkersey / the-alegbra-of-typescript.md
Last active October 17, 2021 06:08
The Algebra of [Type,Script]

Algebra

Symbols Operations Laws
0, 1, 2, x, y, z, ... +, –, x, ÷, ... 0 + x = x, ...

Algebra

Symbols Operations Laws
{-# LANGUAGE DeriveFunctor #-}
module Main where
type Algebra f a = f a -> a
type Coalgebra f a = a -> f a
newtype Fix f = In { out :: f (Fix f) }
@mbrandonw
mbrandonw / gist:ba93c363f67291c2b5ec
Last active November 22, 2021 22:04
First attempt at Functor protocol in Swift
protocol Functor {
func fmap <A, B> (Self<A>, A -> B) -> Self<B>
// ^ ERROR: Cannot specialize non-generic type '`Self`'
}
enum Maybe<A> : Functor {
case Nothing
case Just(A)
func fmap<B>(x: Maybe<A>, f: A -> B) -> Maybe<B> {