Skip to content

Instantly share code, notes, and snippets.

@jtobin
jtobin / ordered.hs
Created July 16, 2015 00:00
longest ordered word in a dictionary
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
@jtobin
jtobin / keybase.md
Created July 15, 2015 21:27
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:dd2efbb73c7c077657cf
Last active August 29, 2015 14:06
super-simple language and type system
{-# 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
{-# 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
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
module HOAS where
data Expr =
Lit Int
| Add Expr Expr
| Let Expr (Expr -> Expr)
instance Num Expr where
{-# 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
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
{-# LANGUAGE BangPatterns #-}
import Control.DeepSeq
import qualified Data.Vector.Unboxed as U
import System.Random.MWC
import Control.Monad
import Criterion.Main
import Criterion.Config
newtype AffineTransform = AffineTransform {
@jtobin
jtobin / gist:5651280
Last active December 17, 2015 18:09
Portfolio grabbin'
{-# OPTIONS_GHC -Wall #-}
import Data.Function
import Data.List
main :: IO ()
main = print $ minimumBy (compare `on` sumDiffs) portfolios
-- Data ------------------------------------------------------------------------
@jtobin
jtobin / gist:4130700
Created November 22, 2012 11:33
praxis list union/intersection main
=== prop_i0ResultElementsAreInBoth from ui.hs:64 ===
+++ OK, passed 1000 tests.
=== prop_i1ResultElementsAreInBoth from ui.hs:68 ===
+++ OK, passed 1000 tests.
=== prop_i2ResultElementsAreInBoth from ui.hs:72 ===
+++ OK, passed 1000 tests.
=== prop_u0ResultElementsInAtLeastOne from ui.hs:77 ===