title |
---|
k-CAS for sweat-free concurrent programming |
k-CAS for sweat-free concurrent programming
Vesa Karvonen
title |
---|
k-CAS for sweat-free concurrent programming |
Vesa Karvonen
// 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/ |
// This is a very brief and incomplete sketch of how the technique used in | |
// | |
// Effectful OCaml with Objects and Variants | |
// https://github.com/polytypic/rea-ml#effectful-ocaml-with-objects-and-variants | |
// | |
// could be translated to F#. The following F# will likely make more sense after | |
// reading the introduction that you'll find by following the above link. | |
[<AutoOpen>] | |
module Rea = |
// 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] |
;; 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: |
;; 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 |
;; ----------------------------------------------------------------------------- | |
;; Unit type | |
Unit :> { | |
type t; | |
one : t; | |
} = { | |
type t = bool; | |
one = true; | |
}; |
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|] |
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") |