Skip to content

Instantly share code, notes, and snippets.

View alarbada's full-sized avatar

Guillem alarbada

View GitHub Profile
@alarbada
alarbada / GADTs.res
Created August 16, 2021 09:44
Rescript syntax for GADTs
// Sources
// https://stackoverflow.com/questions/58964775/pattern-matching-on-a-gadt-fails
// GADTs in rescript.
// GADTs are cool. Here's an example of a function with polymorphic return type.
// The thing is that the syntax is buried somewhere I don't remember, and the
// docs won't say anything because this is sort of black magic. Apply with care.
type rec prim<'t> =
@alarbada
alarbada / do-notation.ts
Last active March 23, 2021 11:44
Typescript with F# computation expressions experiment
// Extended from https://apoberejnyi.medium.com/do-notation-for-either-in-typescript-c207e5987b7a
// Library
type Option<T> = T | null
class OptionError extends Error {
constructor() {
super()
}
@alarbada
alarbada / Nominal.ts
Last active March 21, 2021 21:14
Typescript nominal types with classes
import * as D from 'io-ts/Decoder'
import * as fp from 'fp-ts/function'
// Nominal types without much ceremony: "class" types
// AKA I want to convert typescript types into fsharp types while using
// typescript
// Not much syntax needed, so they are easy to create. That's what Fable uses to
// construct their own records and DUs.
class UserId {