Skip to content

Instantly share code, notes, and snippets.

-- | Fun inspired by Selective
-- http://hackage.haskell.org/package/selective
module FreeSelective where
import Control.Monad (MonadPlus (..))
import Data.Functor.Compose
import GHC.Exts (Constraint)
import Data.Map (Map)
import qualified Data.Map as Map
import Prelude
import scala.annotation.tailrec
import scala.collection.immutable.SortedMap
import scala.collection.mutable
import scala.language.higherKinds
import scala.util.Random
import scala.util.control.TailCalls.{TailRec, done}
sealed trait KArrow[F[_], A, B] extends Product with Serializable
object KArrow {
final case class KMap[F[_], A, B](f: A => B) extends KArrow[F, A, B]
module Inj
import Decidable.Equality
import Decidable.Order
-- These definitions would go in some stdlib
public export
interface Equivalence ty inj => Inj (ty : Type) (inj : ty -> ty -> Type) where
useInj : {x, y: ty} -> inj x y -> x = y
@ejconlon
ejconlon / ElabInj.idr
Created March 14, 2021 00:05
Idris2 elaboration for injectivity
-- From ShinKage on FP Slack
mapName : (String -> String) -> Name -> Name
mapName f (UN n) = UN (f n)
mapName f (MN n i) = (MN (f n) i)
mapName f (NS ns n) = (NS ns (mapName f n))
mapName f (DN n realn) = (DN (f n) realn)
mapName f (RF n) = RF (f n)
appTyCon : List String -> Name -> TTImp
appTyCon ns n = foldl (\tt, v => `(~(tt) ~(IBindVar EmptyFC v))) (IVar EmptyFC n) ns
@ejconlon
ejconlon / BacktrackingStateSearch.hs
Created November 5, 2022 17:32
Backtracking state with LogicT
-- | 'LogicT' is a great monad transformer for backtracking control,
-- but if you just layer with a 'State' monad, you won't backtrack state.
-- By that I mean at all choice points '(<|>)' or 'interleave', we will
-- save part of the state and reset it when retrying alternative branches.
module BacktrackingStateSearch
( TrackSt (..)
, Track
, observeManyTrack
, runManyTrack
) where
// Go to twitter.com and paste this into the js console to block all verified users (slowly)
class CheckieBlock {
constructor() {
this.waitMs = 10*1000;
this.jitMs = 2*1000;
this.blockLimit = 1000;
this.seen = new Set();
}
sleep() {