Skip to content

Instantly share code, notes, and snippets.

View hellwolf's full-sized avatar

Miao ZhiCheng hellwolf

View GitHub Profile
@Lev135
Lev135 / Optics.md
Last active October 7, 2023 10:41
Writing profunctor optics by the same template

Writing profunctor optics by the same template

All of the profunctor optics kind have the same, very simple, pattern:

type AnOptic p s t a b = p a b -> p s t
type Optic c s t a b = forall p. c p => AnOptic p s t a b

type Iso s t a b = Optic Profunctor s t a b
@simonmichael
simonmichael / a.bash
Created July 8, 2023 17:56
options parsing in bash
declare -A FLAGS
declare -a ARGS
while [[ $# -gt 0 ]]; do
key="$1"
@VictorTaelin
VictorTaelin / implementing_fft.md
Last active April 30, 2024 05:32
Implementing complex numbers and FFT with just datatypes (no floats)

Implementing complex numbers and FFT with just datatypes (no floats)

In this article, I'll explain why implementing numbers with just algebraic datatypes is desirable. I'll then talk about common implementations of FFT (Fast Fourier Transform) and why they hide inherent inefficiencies. I'll then show how to implement integers and complex numbers with just algebraic datatypes, in a way that is extremely simple and elegant. I'll conclude by deriving a pure functional implementation of complex FFT with just datatypes, no floats.

@ttesmer
ttesmer / AD.hs
Last active March 19, 2024 03:04
Automatic Differentiation in 38 lines of Haskell using Operator Overloading and Dual Numbers. Inspired by conal.net/papers/beautiful-differentiation
{-# LANGUAGE TypeSynonymInstances #-}
data Dual d = D Float d deriving Show
type Float' = Float
diff :: (Dual Float' -> Dual Float') -> Float -> Float'
diff f x = y'
where D y y' = f (D x 1)
class VectorSpace v where
zero :: v
@Lysxia
Lysxia / Adjunction.hs
Created April 17, 2020 13:07
The Cont adjunction
{-# LANGUAGE
TypeOperators, -- Type-level infix operators, here (<-:)
PolyKinds, -- Kind-polymorphic classes. (You can also instantiate all k and h to Type)
ScopedTypeVariables, -- Extend the scope of type variables to the body of a function
InstanceSigs, -- Type signatures on instance methods
MultiParamTypeClasses, -- Self-explanatory
FlexibleContexts, -- Allows constraints like (Adjunction (->) d f g) where the first argument is not a type variable
AllowAmbiguousTypes, -- unit and counit each don't mention one of the type class parameters
TypeApplications -- To use functions with ambiguous types
@yelouafi
yelouafi / algebraic-effects-series-1.md
Last active February 24, 2024 16:03
Operational Introduction to Algebraic Effects and Continuations

Algebraic Effects in JavaScript part 1 - continuations and control transfer

This is the first post of a series about Algebraic Effects and Handlers.

There are 2 ways to approach this topic:

  • Denotational: explain Algebraic Effects in terms of their meaning in mathematics/Category theory
  • Operational: explain the mechanic of Algebraic Effects by showing how they operate under a chosen runtime environment

Both approaches are valuables and give different insights on the topic. However, not everyone (including me), has the prerequisites to grasp the concepts of Category theory and Abstract Algebra. On the other hand, the operational approach is accessible to a much wider audience of programmers even if it doesn't provide the full picture.