Skip to content

Instantly share code, notes, and snippets.

View fogfish's full-sized avatar

fogfish

View GitHub Profile
@fogfish
fogfish / euclidean_arm64.s
Created March 21, 2024 14:20
Square Euclidean Distance - SIMD ARM NEON
#include "textflag.h"
// func EuclideanF32(a, b, c []float32) float32
TEXT ·EuclideanF32(SB), NOSPLIT, $0
MOVD a_base + 0(FP), R0
MOVD b_base + 24(FP), R1
MOVD c_base + 48(FP), R2
MOVD a_size + (8)(FP), R20
MOVD $4, R8
Protocol Primitive Client-side Server-side
request writer morphism reader morphism
HTTP Method ø.GET
declares the verb of HTTP request
ƒ.GET
matches the verb of HTTP request and fails with error if the verb does not match the expected one.
URI ø.URI(string)
specifies target URI for HTTP request. The combinator uses absolute URI to specify target host and endpoint.
ƒ.URI(string)
matches URL path from HTTP request. The combinator considers the URI path as an ordered sequence of segments, which are matched against a given pattern or uses a lens to extract value into the context. It fails if the path does not match the expected one.
URI Query ø.Params(any)
ø.Param[T Literals](string, T)
lifts the flat structure or individual values into query parameters of specified URI.
`ƒ.Params
@fogfish
fogfish / error-behaviour.go
Last active November 4, 2022 13:35
Example of behaviour used for “Assert errors for behavior, not type”
//
// See the post: https://tech.fog.fish/2022/07/05/assert-golang-errors-for-behavior.html
//
// ErrorCodes provides a raw code originared by the failed package
type ErrorCode interface{ ErrorCode() string }
// ErrorType is the primary identifier (IRI) for the problem type, defined by the ontology
type ErrorType interface{ ErrorType() string }
package main
import (
"fmt"
"strings"
)
//
//
type HKT[F, A any] interface {
class HKT<F, A> {}
interface Functor<F> {
map<A, B>(f: (a: A) => B, fa: HKT<F, A>): HKT<F, B>
}
type Seq<A> = HKT<'Seq', A>
type Abc<A> = HKT<'Abc', A>
type seq<A> = Array<A>
package main
import (
"fmt"
"strconv"
)
//
//
func filter[A any](f func(A) bool, a A) A {
/*
SeqEq is a heterogeneous product of Seq and Eq laws.
It composes two types together that "knows" how to compare sequences.
*/
type SeqEq[S, T any] struct {
Seq[S, T]
Eq[T]
}
/*
Seq defines fundamental general purpose sequence
*/
type Seq[S any, T any] interface {
Head(S) *T
Tail(S) S
IsVoid(S) bool
}
type Foldable[T any] interface {
Fold(T, []T) T
}
type Semigroup[T any] interface {
Combine(T, T) T
}
type Folder[T any] struct{ Semigroup[T] }
/*
ContraMapEq is a combinator that build a new instance of type trait Eq[B] using
existing instance of Eq[A] and f: b ⟼ a
*/
type ContraMapEq[A, B any] struct{ Eq[A] }
// implementation of contra variant functor
func (c ContraMapEq[A, B]) FMap(f func(B) A) Eq[B] {
return FromEq[B](func(a, b B) bool {