Skip to content

Instantly share code, notes, and snippets.

View Kazark's full-sized avatar

Keith Pinson Kazark

  • Undisclosed
View GitHub Profile
@amrali
amrali / hkt.cpp
Created September 17, 2018 00:14 — forked from jhaberstro/hkt.cpp
Functor, Maybe, and Higher-Kinded Types in C++
// Example program
#include <iostream>
#include <string>
#include <vector>
#include <type_traits>
//---------------------
// Maybe and MyVector, two totally unrelated classes whose only commanilty is that they are both type constructors of the same arity (e.g. 1) and order (e.g. 1).
//---------------------
template< typename T >
@ekmett
ekmett / CEK.hs
Created July 22, 2018 17:53
A more strongly typed CEK machine
{-# Language StrictData #-}
{-# Language GADTs #-}
{-# Language DeriveTraversable #-}
{-# Language LambdaCase #-}
module CEK where
import Control.Monad (ap)
import Data.Maybe
import Data.Void
@ekmett
ekmett / CEK.hs
Created July 22, 2018 17:52
Simple CEK Machine
{-# language StrictData #-}
module CEK where
-- C -- Control
-- E -- Environment
-- (S) -- Store
-- K -- Continuation
data Exp
= Var String
@raulraja
raulraja / dstagless.kt
Last active December 15, 2018 01:23
Tagless data source strategies with Arrow
import arrow.Kind
import arrow.core.Option
import arrow.core.left
import arrow.core.right
import arrow.effects.typeclasses.Async
import arrow.typeclasses.ApplicativeError
data class UserId(val value: String)
data class User(val userId: UserId)
data class Task(val value: String)
@t1m0thyj
t1m0thyj / timeInterval.fs
Last active May 11, 2022 10:56
Implementation of time interval problem in F# with error handling
// Coded online at https://repl.it/@t1m0thyj/F-Scratchpad-1
open System
let dateStr = "1/1/2000,2/29/2000,2/29/2004,2/29/2008,2/29/2012,2/29/2016,3/14/15 9:26:53"
let getDayDiff (date1:string, date2:string) =
let couldParse, startDate = DateTime.TryParse date1
if (not couldParse) then failwithf "Date '%s' is not valid" date1
let couldParse, endDate = DateTime.TryParse date2
open Printf
module Syntax = struct
type t =
| Unit
| Boolean of bool
| Number of int
| Name of string
| Divide of t * t
@ploeh
ploeh / Tuple2.fs
Last active December 2, 2022 14:11
Helpful functions for working with pairs in F#
module Tuple2
let replicate x = x, x
let curry f x y = f (x, y)
let uncurry f (x, y) = f x y
let swap (x, y) = (y, x)
Control.Arrow
=============
"compose/arr" forall f g .
(arr f) . (arr g) = arr (f . g)
"first/arr" forall f .
first (arr f) = arr (first f)
"second/arr" forall f .
second (arr f) = arr (second f)
"product/arr" forall f g .
arr f *** arr g = arr (f *** g)
@kmizu
kmizu / parsers.nim
Created July 1, 2016 00:51
parser combinator library in Nim
import strutils
import lists
import re
type
Parser[T] = proc(input: string): Maybe[(T, string)]
Maybe*[T] = object
value: T
hasValue: bool
@gelisam
gelisam / exchange-formats.md
Last active September 30, 2023 17:50
A list of every data exchange formats I could find

At work, I just spent the last few weeks exploring and evaluating every format I could find, and my number one criteria was whether they supported sum types. I was especially interested in schema languages in which I could describe my types and then some standard specifies how to encode them using an on-the-wire format, usually JSON.

  1. Swagger represents sum types like Scala does, using subtyping. So you have a parent type EitherIntString with two subtypes Left and Right represented as {"discriminator": "Left", value: 42} and {"discriminator": "Right", value": "foo"}. Unfortunately, unlike in Scala in which the parent type is abstract and cannot be instantiated, in Swagger it looks like the parent type is concrete, so when you specify that your input is an EitherIntString, you might receive {"discriminator": "EitherIntString"} instead of one of its two subtypes.
  2. JSON-schema supports unions, which isn't quite the same thing as sum types because