Skip to content

Instantly share code, notes, and snippets.

@beezee
beezee / Qcc.hs
Created February 19, 2022 20:52
Quantified constrained constraints
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE QuantifiedConstraints #-}
import Data.Kind (Constraint, Type)
import Data.Monoid (Sum(..))
@beezee
beezee / Script.hs
Created May 30, 2021 02:04
Haskell script boilerplate
{- stack script
--resolver lts-17.13
--install-ghc
--ghc-options -Wall
--ghc-options -Werror
--package "package1 package2 etc"
-}
-- informed by https://wespiser.com/posts/2020-02-02-Command-Line-Haskell.html
module Script where
@beezee
beezee / notes.md
Created March 7, 2020 19:58
latex setup
@beezee
beezee / shipments.pi
Created December 17, 2019 17:25
shipments-example
new geolocations, milestones. (Shipments[geolocations, milestones] | Orders[milestones] | OceanInsights[geolocations])
Shipments[g, m] := g(geo).Shipments_Recv_Geolocation[g, m, geo] + tau.new milestone.Shipments_Send_Milestone[g, m, milestone]
Shipments_Recv_Geolocation[g, m, geo] := tau.Shipments[g, m]
Shipments_Send_Milestone[g, m, ms] := m<ms>.Shipments[g, m]
Orders[m] := m(milestone).Orders_Recv_Milestone[m, milestone]
new oq, qr, n, req. (Init[oq, req] | S[oq, qr] | I[qr, n] | F[n])
S[oq, qr] := oq(req).new query.S_query[qr, query]
S_query[qr, query] := qr<query>.S[qr, qr]
I[qr, n] := qr(query).new response.I_notice[qr, n, response]
I_notice[qr, n, response] := n<response>.I_respond[qr, n, response]
I_respond[qr, n, resp] := qr<resp>.I[qr, n]
F[n] := n(resp).F_recv[n]
F_recv[n] := τ.F[n]
Init[qr, req] := qr<req>
// Start writing your ScalaFiddle code here
trait Foo[A] {
def apply: A
}
trait Bar[I] {
def apply(i: I): Unit
}
trait FooBarDependencies {}
@beezee
beezee / gist:a2721b37c93952e7b63673f9738b0cb1
Created October 19, 2018 13:38
simple refactorings, prod/cop
a -> (b, c) ~ (a -> b, a -> c)
(a | b) -> c ~ (a -> c, b -> c)
bc^a = b^a*c^a
c^(a+b) = c^a*c^b
a=2;b=2;c=3;
(2*3)^2 = 36 = (2^2)*(3^2)
3^(2+2) = 81 = 3^2*3^2
import scalaz.{Alt, Apply, ApplicativePlus, Arrow, Choice, Decidable, Divide, Semigroup}
object Derive {
implicit def ArrowInstanceCovariant[F[_, _], From](implicit A: Arrow[F]): Apply[F[From, ?]] = new Apply[F[From, ?]] {
def map[A, B](fa: F[From, A])(f: A => B): F[From, B] = A.compose(A.arr(f), fa)
def ap[A,B](fa: => F[From, A])(f: => F[From, A => B]): F[From, B] =
A.mapsnd(A.combine(f, fa))(t => t._1(t._2))
}
implicit def ArrowChoiceInstance[F[_, _], To](implicit A: Arrow[F], C: Choice[F]): Decidable[F[?, To]] = new Decidable[F[?, To]] {
@beezee
beezee / axo-transformation-chains.scala
Created October 7, 2018 21:56
Arity abstracted Prod/Cop of unrelated * -> * and their *s with adjoining transformations and operations in terms of them
import cats.arrow.FunctionK
import cats.{Functor, Monad}
import cats.syntax.either._
import scala.language.higherKinds
trait AxoAdjunction3[F1[_], F2[_], F3[_], A1, A2, A3] {
type Prod = (F1[A1], F2[A2], F3[A3])
type Cop = (F1[A1] Either (F2[A2] Either F3[A3]))
def r1: (F1 FunctionK F2)
def l1: (F2 FunctionK F1)
@beezee
beezee / what-does-it-mean.scala
Created September 27, 2018 04:50
what does it mean?
// List[Either[A, B]] <=> (List[A], List[B])
// Option[These[A, B]] <=> (Option[A], Option[B])
// what does it mean that this compiles? what can be derived as a relationship? what can be induced?
trait Iso[A, B] {
def from(a: A): B
def to(b: B): A
}
sealed trait These[A, B]