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
declare -A FLAGS | |
declare -a ARGS | |
while [[ $# -gt 0 ]]; do | |
key="$1" |
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.
{-# 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 |
{-# 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 |
This is the first post of a series about Algebraic Effects and Handlers.
There are 2 ways to approach this topic:
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.