Skip to content

Instantly share code, notes, and snippets.

View polytypic's full-sized avatar

Vesa Karvonen polytypic

  • Helsinki, Finland
View GitHub Profile
// So called van Laarhoven lenses, named after their discoverer, have a number
// of nice properties as explained by Russell O'Connor:
//
// http://r6.ca/blog/20120623T104901Z.html
//
// Unfortunately their typing (in Haskell)
//
// type Lens s t a b = forall f. Functor f => (a -> f b) -> (s -> f t)
//
// seems to be well outside of what can be achieved in F#.
@polytypic
polytypic / hyphenated.js
Last active November 20, 2016 11:23
Finnish language hyphenation hack with React.
import * as R from "ramda"
import React from "react"
// Rules from http://www.cse.tkk.fi/fi/opinnot/CSE-A1121/English2015/harjoitukset/kierros_2/harj_1/index.html
// Nope, I haven't rigorously checked that I implemented the rules correctly.
const consonantRule =
R.replace(/([aeiouyäö])([b-df-hj-np-tvwxz]*)([b-df-hj-np-t-tvwxz])([aeiouyäö])/gi,
"$1$2\xAD$3$4")
@polytypic
polytypic / optics.re
Created May 15, 2017 06:46
Experimental optics in Reason (avoiding higher-kinded abstractions)
let id x => x;
let always x _ => x;
let (>>) f g x => g (f x);
let (<|) f x => f x;
module Option = {
type t 'a = option 'a;
let toArray xO => switch xO {
| None => [||]
| Some x => [|x|]
@polytypic
polytypic / prelude-extra.1ml
Last active March 20, 2018 06:05
Profunctor optics in 1ML --- WORK-IN-PROGRESS!
;; -----------------------------------------------------------------------------
;; Unit type
Unit :> {
type t;
one : t;
} = {
type t = bool;
one = true;
};
@polytypic
polytypic / tiv.1ml
Last active November 18, 2019 07:20
Type indexed values in 1ML
;; Type indexed values in 1ML
;;
;; This is a very simple experiment at encoding type-indexed values in 1ML.
;;
;; Background:
;;
;; https://people.mpi-sws.org/~rossberg/1ml/
;; http://repository.readscheme.org/ftp/papers/zheyang-icfp98.pdf
;;
;; Run as:
@polytypic
polytypic / amateurfunctor-optics.1ml
Last active April 2, 2018 13:26
Amateurfunctor optics in 1ML --- WORK-IN-PROGRESS!
;; Amateurfunctor optics in 1ML --- WORK-IN-PROGRESS!
;;
;; Background:
;;
;; https://people.mpi-sws.org/~rossberg/1ml/
;; http://r6.ca/blog/20120623T104901Z.html
;;
;; Run as:
;;
;; ./1ml prelude.1ml amateurfunctor-optics.1ml
@polytypic
polytypic / Hoas.scala
Last active December 8, 2020 18:51
Curious case of GADTs in Scala
// Below is a simple attempt at using GADTs in Scala based on
//
// https://github.com/palladin/idris-snippets/blob/master/src/HOAS.idr
object Hoas {
// With case classes one can directly write down what looks like a GADT:
sealed trait Expr[A]
final case class Val[A](value: A) extends Expr[A]
final case class Bin[A, B, C](bin: (A, B) => C, lhs: Expr[A], rhs: Expr[B])
extends Expr[C]

Learning day: ReDiSL

Logistics team held a "learning day" on Thursday 2021-03-04 where we could spend one full day on a project or tutorial of our choosing. I worked on a little proof-of-concept project I dubbed ReDiSL or Redis DSL. This is a little writeup on the topic.

The motivation for working on the Redis DSL or ReDiSL was that it could make for a nice way to work with Redis especially when one is doing

@polytypic
polytypic / Zio.fsx
Last active January 16, 2023 14:42
Zio like monad in F#
// Computations with extensible environment, error handling, and asynchronicity
// I recently reviewed some F# code that turned out to be using
//
// Dependency Interpretation
// https://fsharpforfunandprofit.com/posts/dependencies-4/
//
// and got thinking about whether one could construct a usable Zio like monad
//
// https://zio.dev/
@polytypic
polytypic / .gitignore
Last active July 6, 2024 17:56
Recursive generator using C++20 coroutines
build