Skip to content

Instantly share code, notes, and snippets.

View tschuchortdev's full-sized avatar
🐛
master of bugs

Thilo Schuchort tschuchortdev

🐛
master of bugs
  • inoio GmbH
  • Hamburg, Germany
View GitHub Profile
@johnchandlerburnham
johnchandlerburnham / ATaxonomyOfSelfTypes.md
Last active May 2, 2024 16:33
A Taxonomy of Self Types

A Taxonomy of Self-Types

Part I: Introduction to Self-Types

Datatypes in the Formality programming language are built out of an unusual structure: the self-type. Roughly speaking, a self-type is a type that can depend or be a proposition on it's own value. For instance, the consider the 2 constructor datatype Bool:

@chrisdone
chrisdone / DBAPI.hs
Last active April 10, 2022 07:26
Defaulting fields in a record in Haskell
{-# LANGUAGE DataKinds #-}
-- | My database API.
module DBAPI where
import Data.Defaults
data ConnSpec p = ConnSpec
{ username :: !(Required p String)
@TOTBWF
TOTBWF / MTLDerivingVia.hs
Last active November 6, 2021 16:59
Deriving MTL classes using -XDerivingVia
-- |
-- Module : Lift
-- Copyright : (c) Reed Mullanix 2019
-- License : BSD-style
-- Maintainer : reedmullanix@gmail.com
--
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
@andymatuschak
andymatuschak / States-v3.md
Last active May 1, 2024 12:32
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@jibsen
jibsen / addflags.md
Created June 10, 2016 18:35
CMake functions to add compiler flags

Code

Here are two simple CMake functions that take a list of compiler flags, and append those that do not result in an error when used to the supplied variable.

Depending on which version of CMake you need to support, you might want to look into the COMPILE_FLAGS property and target_compile_options().

@mikehearn
mikehearn / Kryo Kotlin class serialiser.kt
Created December 17, 2015 10:53
A Kryo serialiser that lets you serialise immutable classes like "class Foo(val a: Int, val b: Bar)" without bypassing the c'tor.
interface SerializeableWithKryo
class ImmutableClassSerializer<T : SerializeableWithKryo>(val klass: KClass<T>) : Serializer<T>() {
val props = klass.memberProperties.sortedBy { it.name }
val propsByName = props.toMapBy { it.name }
val constructor = klass.primaryConstructor!!
init {
// Verify that this class is immutable (all properties are final)
assert(props.none { it is KMutableProperty<*> })