Skip to content

Instantly share code, notes, and snippets.

@jtobin
jtobin / up-bench.hoon
Last active August 26, 2021 22:17
+up benchmarks
:- %say
|= $: *
[ben=?(%put %vip %get %bot %del) ~]
[min=(list (pair @ @)) mit=(pry @ _~) nit=_| ~]
==
:- %noun
:: +up benchmarks
::
=/ pi (up @ _~)
::
@jtobin
jtobin / error.log
Created July 9, 2019 08:35
~zod testnet scrollback
worker_send_replace 47276 hole
worker_send_replace 47276 crud
%hole event failed:
bail: exit
/:<[18.151 15].[18.169 27]>
/:<[18.152 15].[18.169 27]>
/:<[18.153 15].[18.169 27]>
/:<[18.153 31].[18.153 46]>
/:<[18.224 3].[18.237 13]>
/:<[18.225 3].[18.237 13]>
@jtobin
jtobin / foo.hs
Created February 15, 2016 21:39
Independence and Applicativeness
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
import Control.Applicative.Free
import Control.Monad
import Control.Monad.Free
import Control.Monad.Primitive
import System.Random.MWC.Probability (Prob)
import qualified System.Random.MWC.Probability as MWC
@jtobin
jtobin / CPS.hs
Created August 4, 2018 23:35
Some CPS transformations.
-- see: http://matt.might.net/articles/cps-conversion
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as T
import Data.Unique
import qualified Text.PrettyPrint.Leijen.Text as PP
@jtobin
jtobin / recursion_schemes.hs
Created September 6, 2015 00:58
An illustration of the recursion-schemes library.
{-# LANGUAGE DeriveFunctor #-}
import Data.List.Ordered (merge)
import Data.Functor.Foldable
import Prelude hiding (Foldable, succ)
data NatF r =
ZeroF
| SuccF r
deriving (Show, Functor)
@jtobin
jtobin / histo-futu.hs
Created February 9, 2016 02:21
Time-traveling recursion schemes
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeFamilies #-}
import Control.Comonad.Cofree
import Control.Monad.Free
import Data.Functor.Foldable
oddIndices :: [a] -> [a]
oddIndices = histo $ \case
Nil -> []
@jtobin
jtobin / pp-comonad.hs
Created October 27, 2016 00:57
Probabilistic programming using comonads.
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
import Control.Comonad
import Control.Comonad.Cofree
import Control.Monad
import Control.Monad.ST
@jtobin
jtobin / Prob.hs
Created October 18, 2016 08:52
A simple embedded probabilistic programming language
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
import Control.Monad
import Control.Monad.Free
import qualified System.Random.MWC.Probability as MWC
data ModelF r =
BernoulliF Double (Bool -> r)
| BetaF Double Double (Double -> r)
@jtobin
jtobin / fix-free-cofree.hs
Created December 9, 2015 06:13
Fix, Free, and Cofree
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
import Prelude hiding (succ)
newtype Fix f = Fix (f (Fix f))
deriving instance (Show (f (Fix f))) => Show (Fix f)
@jtobin
jtobin / Metropolis.hs
Created October 1, 2016 11:13
A Metropolis sampler.
module Metropolis where
import Control.Monad
import Control.Monad.Primitive
import System.Random.MWC as MWC
import System.Random.MWC.Distributions as MWC
propose :: [Double] -> Gen RealWorld -> IO [Double]
propose location gen = traverse (perturb gen) location where