Skip to content

Instantly share code, notes, and snippets.

View gist:b8ff5ef03855603bcb73
module Main where
import Control.Monad
import Control.Monad.Primitive
import System.Environment
import System.Random.MWC
data Child = Boy | Girl deriving (Eq, Show)
instance Variate Child where
View gist:89d741df8aaaa33eb567
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TypeFamilies #-}
module Minimal where
import Control.Applicative
import Data.Graph
View gist:3fc26d852af9e82e378e
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
module HOAS where
data Expr =
Lit Int
| Add Expr Expr
| Let Expr (Expr -> Expr)
instance Num Expr where
View gist:e3e945f3c761cbc6ad43
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
{-# LANGUAGE RankNTypes #-}
module PHOAS where
data Expr a =
Lit Int
| Var a
@jtobin
jtobin / gist:dd2efbb73c7c077657cf
Last active Aug 29, 2015
super-simple language and type system
View gist:dd2efbb73c7c077657cf
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
{-# LANGUAGE PatternGuards #-}
import Control.Applicative
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.Monoid
import Data.Traversable
import System.Exit
@jtobin
jtobin / ordered.hs
Created Jul 16, 2015
longest ordered word in a dictionary
View ordered.hs
module Ordered where
import Data.Function (on)
import Data.List (sort, maximumBy)
longestOrdered :: Ord a => [[a]] -> Maybe [a]
longestOrdered dict = safeMaximumBy (compare `on` length)
[word | word <- dict, sort word == word]
safeMaximumBy :: (a -> a -> Ordering) -> [a] -> Maybe a
View keybase.md

Keybase proof

I hereby claim:

  • I am jtobin on github.
  • I am jtobin (https://keybase.io/jtobin) on keybase.
  • I have a public key whose fingerprint is 3422 6DCF 974D 5AF1 2114 488A 710A 5FDA E32D 77E7

To claim this, I am signing this object:

@jtobin
jtobin / gist:3865601
Created Oct 10, 2012
Incorporating parallelism
View gist:3865601
import Control.Monad.Par
-- Using the Par monad
logRosenbrockDensity :: [Double] -> Double
logRosenbrockDensity [x0, x1] = runPar $ do
[a, b] <- sequence [new, new]
fork $ put a (-100*(x1 - (x0^2))^2 / 20)
fork $ put b (-0.05*(1-x0)^2)
[a', b'] <- sequence [get a, get b]
return $ a' + b'
@jtobin
jtobin / gist:3865854
Created Oct 10, 2012
Simple benchmark
View gist:3865854
$ time ./Rosenbrock 500 > trace.dat # using an ensemble containing 200 particles
(flat-mcmc) Rosenbrock density
20259 / 100000 (0.20259) proposals accepted
real 0m0.428s
user 0m0.367s
sys 0m0.016s
@jtobin
jtobin / gist:3865828
Created Oct 10, 2012
Single-threaded Rosenbrock
View gist:3865828
logRosenbrockDensity :: [Double] -> Double
logRosenbrockDensity [x0, x1] = (-1)*(100*(x1 - (x0^2))^2 + (1 - x0)^2) / 20
You can’t perform that action at this time.