Skip to content

Instantly share code, notes, and snippets.

@beezee
beezee / Script.hs
Created May 30, 2021
Haskell script boilerplate
View Script.hs
{- 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
View notes.md
@beezee
beezee / shipments.pi
Created Dec 17, 2019
shipments-example
View shipments.pi
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]
View Query-Respond-Notify.pi
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>
View dependents-dependencies.scala
// Start writing your ScalaFiddle code here
trait Foo[A] {
def apply: A
}
trait Bar[I] {
def apply(i: I): Unit
}
trait FooBarDependencies {}
View gist:a2721b37c93952e7b63673f9738b0cb1
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
View arrow-derivation.scala
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 Oct 7, 2018
Arity abstracted Prod/Cop of unrelated * -> * and their *s with adjoining transformations and operations in terms of them
View axo-transformation-chains.scala
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)
View what-does-it-mean.scala
// 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]
View converter.scala
package sample
import scala.language.implicitConversions
import shapeless._
import shapeless.Everywhere
import ops.hlist.{Align, Mapper, Prepend}
import poly._
import record._
import syntax.singleton._
import shapeless.tag