Skip to content

Instantly share code, notes, and snippets.

Jared Tobin jtobin

Block or report user

Report or block jtobin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jtobin
jtobin / error.log
Created Jul 9, 2019
~zod testnet scrollback
View error.log
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 Feb 15, 2016
Independence and Applicativeness
View foo.hs
{-# 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 Aug 4, 2018
Some CPS transformations.
View CPS.hs
-- 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 Sep 6, 2015
An illustration of the recursion-schemes library.
View recursion_schemes.hs
{-# 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 Feb 9, 2016
Time-traveling recursion schemes
View histo-futu.hs
{-# 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 Oct 27, 2016
Probabilistic programming using comonads.
View pp-comonad.hs
{-# 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 Oct 18, 2016
A simple embedded probabilistic programming language
View Prob.hs
{-# 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 Dec 9, 2015
Fix, Free, and Cofree
View fix-free-cofree.hs
{-# 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 Oct 1, 2016
A Metropolis sampler.
View Metropolis.hs
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
@jtobin
jtobin / speedy.hs
Last active Nov 12, 2016
such speed
View speedy.hs
import Data.Vector.Unboxed as U
import System.Random.MWC
main :: IO ()
main = withSystemRandom . asGenIO $ \gen -> do
x <- uniformVector gen 10000000 :: IO (U.Vector Double)
print (U.sum x)
-- jtobin@castor:~/sandbox$ time ./Rand +RTS -s
-- 4999721.338394913
You can’t perform that action at this time.