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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let xn = (x, n) => x ** (n - 1n); // TODO: has a probably O(n!) complexity. More efficient algorithm needed. | |
function mod(x, n) { | |
const _xn = xn(x, n); | |
return (_xn - 1n) % n === 0n; | |
} | |
function withTimer(fn, timeName = 'Run time') { | |
return (...args) => { | |
console.time(timeName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* chacha20 - 256 bits */ | |
// Written in 2014 by Devi Mandiri. Public domain. | |
// | |
// Implementation derived from chacha-ref.c version 20080118 | |
// See for details: http://cr.yp.to/chacha/chacha-20080128.pdf | |
function U8TO32_LE(x, i) { | |
return x[i] | (x[i+1]<<8) | (x[i+2]<<16) | (x[i+3]<<24); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
page ,132 | |
title memcpy - Copy source memory bytes to destination | |
;*** | |
;memcpy.asm - contains memcpy and memmove routines | |
; | |
; Copyright (c) Microsoft Corporation. All rights reserved. | |
; | |
;Purpose: | |
; memcpy() copies a source memory buffer to a destination buffer. | |
; Overlapping buffers are not treated specially, so propogation may occur. |
This is the final part of a series about Algebraic Effects and Handlers.
- Part 1 : continuations and control transfer
- Part 2 : Capturing continuations with Generators
- Part 3 : Delimited continuations
- Part 4 : Implementing Algebraic Effects and handlers
So we've come to the core topic. The reality is that we've already covered most of it in the previous parts. Especially, in the third part, where we saw delimited continuations at work.
Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.
There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.
1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]
struct foo {
struct bar {
int x;
NewerOlder