Skip to content

Instantly share code, notes, and snippets.

Some thoughts on building software

Lately I have been busy reading some new books on Domain Driven Design (DDD) and software architecture -- including a short yet eye-opening one in Python and a great one in F#. At the same time, it seems that more people in the Functional Programming world are looking at more formal approaches to modelling -- some examples here. This has brought some thought from the background of my brain about how we should model, organize, and architect software using the lessons we've learnt from functional programming.

Before moving on, let me be clear about this being just a dump of some thoughts, not always well-defined, definite

@graninas
graninas / haskell_design_patterns.md
Last active September 2, 2023 13:47
Haskell Design Patterns

Design patterns in Haskell

This is a list of patterns. I'm collecting this list with an idea to write a book similar to the GoF book.

My patterns:

  • Typed / Untyped pattern
  • Typed Avatar pattern (see Hydra and Node)
    • Typed Options pattern (see EulerHS)
  • Control Structure pattern (see CLI control structure in Hydra and similar in Node)
@fracek
fracek / CMakeLists.txt
Last active August 12, 2023 13:52
CMake and GTK+ 3
# Thanks to @danger89 and @Ilothar for updating the gist.
# Set the name and the supported language of the project
project(hello-world C CXX)
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 3.10)
# Use the package PkgConfig to detect GTK+ headers/library files
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED gtkmm-3.0)
@sampsyo
sampsyo / fib.ts
Last active August 9, 2023 23:54
function inheritance in TypeScript
// This is a quick demonstration of "function inheritance" as described in
// this paper from Daniel Brown and William Cook.
// http://www.cs.utexas.edu/users/wcook/Drafts/2009/sblp09-memo-mixins.pdf
// Expressed in TypeScript (and without the monads).
// Syntax note: When you write function types in TypeScript, you need to name
// each parameter. But the names don't actually matter, so I just use _. You
// can read `(_:A) => B` as `a -> b` in ML or Haskell syntax.
// In Brown and Cook's Haskell, `type Gen a = a -> a` is a "generator." The
@seanf
seanf / process.kt
Created August 23, 2017 02:12
Execute process from Kotlin
import java.lang.ProcessBuilder.Redirect
import java.util.concurrent.TimeUnit
fun String.runCommand(workingDir: File? = null) {
val process = ProcessBuilder(*split(" ").toTypedArray())
.directory(workingDir)
.redirectOutput(Redirect.INHERIT)
.redirectError(Redirect.INHERIT)
.start()
if (!process.waitFor(10, TimeUnit.SECONDS)) {
@alandipert
alandipert / kahn.clj
Last active June 24, 2023 17:59
Kahn's topological sort in Clojure
;; Copyright (c) Alan Dipert. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns alandipert.kahn
(:require [clojure.set :refer [difference union intersection]]))
@smarr
smarr / truffle-material.md
Last active March 16, 2023 14:06
Truffle: Languages and Material
@ploeh
ploeh / ApiModel.hs
Last active December 24, 2022 22:54
Handling a reservation request in Haskell. Proof of concept
module ApiModel where
import Data.Time (ZonedTime(..), parseTimeM, defaultTimeLocale, iso8601DateFormat)
data ReservationRendition = ReservationRendition
{ rDate :: String
, rName :: String
, rEmail :: String
, rQuantity :: Int }
deriving (Eq, Show, Read)
@stuarthalloway
stuarthalloway / gist:2645453
Created May 9, 2012 15:22
Datomic queries against Clojure collections
;; Datomic example code
(use '[datomic.api :only (db q) :as d])
;; ?answer binds a scalar
(q '[:find ?answer :in ?answer]
42)
;; of course you can bind more than one of anything
(q '[:find ?last ?first :in ?last ?first]
"Doe" "John")
@cy6erGn0m
cy6erGn0m / merge-maps.kt
Created May 20, 2015 14:41
Merge two maps with custom reduce function for Kotlin
private fun <K, V> Map<K, V>.mergeReduce(other: Map<K, V>, reduce: (V, V) -> V = { a, b -> b }): Map<K, V> {
val result = LinkedHashMap<K, V>(this.size() + other.size())
result.putAll(this)
other.forEach { e ->
val existing = result[e.key]
if (existing == null) {
result[e.key] = e.value
}
else {