Skip to content

Instantly share code, notes, and snippets.

View lseppala's full-sized avatar
🪵

Lane Seppala lseppala

🪵
  • GitHub
  • Boulder, Colorado
View GitHub Profile
def hot_potato( queue, num )
def pass_potato potato_queue
passer = potato_queue.pop
potato_queue.insert( 0, passer )
potato_queue
end
def remove_looser( q, n )
list = q
-- You asked why the Haskell implementation is so much slower than the Ruby
-- implementation. Before we do any comparision of X language to Y langage,
-- we *must* do a complexity analysis ("Big-O"). We can't make any
-- comparison of languages if the underlying algorithm isn't the same.
--
-- Let's go through your code and analyze each function's contributing
-- complexity. I'm putting your code in order from outer-most function to
-- inner-most. You could do it vise-versa, but I think this helps
-- illustrate this example best.
{}: # nix-env expects a function
let
# Get nixpkgs (in configuration.nix, use pkgs for this, but this file is standalone
# to test it easier so we have to manually import nixpkgs)
pkgs = import <nixpkgs> {};
# First, get the haskell packages from nixpkgs. In configuration.nix, you
# can use pkgs.haskellngPackages for this of course.
haskellngPackages = pkgs.haskellngPackages;
@lseppala
lseppala / reid.hs
Last active September 25, 2015 18:44
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleInstances #-}
module Main where
class FinalExpr a where
intThing :: Int -> a
stringThing :: String -> a
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Unique (cost=60.36..60.36 rows=1 width=28) (actual time=1.736..1.928 rows=2 loops=1)
-> Sort (cost=60.36..60.36 rows=1 width=28) (actual time=1.735..1.815 rows=1278 loops=1)
Sort Key: ds_sensor.datastream_id, temp."time"
Sort Method: quicksort Memory: 148kB
-> Nested Loop (cost=4.79..60.35 rows=1 width=28) (actual time=0.069..0.876 rows=1278 loops=1)
-> Nested Loop (cost=4.79..40.33 rows=1 width=24) (actual time=0.047..0.107 rows=4 loops=1)
-> Nested Loop (cost=4.64..39.68 rows=3 width=28) (actual time=0.034..0.079 rows=11 loops=1)
-> Nested Loop (cost=4.49..39.04 rows=3
@lseppala
lseppala / Main.hs
Last active November 5, 2015 18:39
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
import Control.Lens
newtype Key model keytype = Key { unKey :: keytype }
deriving (Show, Eq, Ord)
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module Play where
import Control.Monad.Free.VanLaarhovenE
data Logging m = Logging
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module Play where
import Control.Monad.Free.VanLaarhovenE
data Logging m = Logging
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module NestedVL where
import Control.Monad.Free.VanLaarhovenE
data Logging m = Logging
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances #-}
import Control.Arrow ((&&&))
import Data.Functor.Coyoneda
import qualified Control.Monad.Free as F