Skip to content

Instantly share code, notes, and snippets.

View 23Skidoo's full-sized avatar

Mikhail Glushenkov 23Skidoo

View GitHub Profile
@23Skidoo
23Skidoo / Fibs.hs
Created June 23, 2011 18:24
Fibonacci
{-# LANGUAGE BangPatterns #-}
module Main where
zipWith' :: (t -> t1 -> a) -> [t] -> [t1] -> [a]
zipWith' f (!x:xs) (!y:ys) = f x y : zipWith' f xs ys
zipWith' _ _ _ = []
fibs :: [Integer]
fibs = 0 : 1 : zipWith' (+) fibs (tail fibs)
@23Skidoo
23Skidoo / JaneStreet.hs
Created July 1, 2011 11:16
Fun interview question
-- See http://bit.ly/kqOh4B
module Main
where
import Control.Arrow
import Data.Char
zeroOrOne :: Char -> Bool
zeroOrOne = uncurry (||) . ((==) 1 &&& (==) 0) . digitToInt
@23Skidoo
23Skidoo / Aeson.hs
Created July 4, 2011 08:46
Somewhat ugly aeson code
{-# LANGUAGE OverloadedStrings #-}
module Main
where
import Control.Applicative
import Control.Monad (mzero)
import qualified Data.ByteString as B
import qualified Data.Map as M
@23Skidoo
23Skidoo / SharingMap.hs
Created July 4, 2011 15:19
Sharing map (cleaned-up Core listing)
sharingMap1 :: [([a], a, Maybe a)] -> (# Bool, [a] #)
sharingMap1 [] = (# False, [] #);
sharingMap1 ((ds_diz, y1_adI, Nothing):ys) =
let (# ww1_skq, ww2_skr #) = sharingMap1 ys
in case ww1_skq of {
False -> (# False, ds_diz #);
True -> (# True, (y1_adI:ww2_skr) #)
}
sharingMap1 ((ds_diz, y1_adI, Just y2):ys) =
let (# ww1_skq, ww2_skr #) = sharingMap1 ys
@23Skidoo
23Skidoo / OutputSerializtion.hs
Created July 10, 2011 16:12
A sketch of how I intend to do output serialization in `cabal install -j`
module Main
where
import Control.Monad
import Control.Concurrent
import System.IO
import System.Process
yesThread :: Int -> Chan String -> IO ()
yesThread n c = do (_, out, _, _) <- runInteractiveCommand "yes"
@23Skidoo
23Skidoo / test.hs
Created August 14, 2011 22:05
Adventures with the vector package
{-# LANGUAGE TypeFamilies, MultiParamTypeClasses #-}
module Main
where
import Control.Monad ( liftM )
import Data.Char
import qualified Data.Vector.Unboxed as V
import Data.Vector.Generic as G
import qualified Data.Vector.Generic.Mutable as M
@23Skidoo
23Skidoo / output.txt
Created August 14, 2011 22:56
Output serialisation in action
$ cabal install -j2 transformers quickcheck
Resolving dependencies...
[1] Downloading QuickCheck-2.4.1.1...
[2] Downloading transformers-0.2.2.0...
[2] Configuring transformers-0.2.2.0...
[1] Configuring QuickCheck-2.4.1.1...
[2] Building transformers-0.2.2.0...
[2] Preprocessing library transformers-0.2.2.0...
[1] Building QuickCheck-2.4.1.1...
[1] Preprocessing library QuickCheck-2.4.1.1...
@23Skidoo
23Skidoo / MonadTransformers.hs
Created October 7, 2011 22:39
Dabbling with monad transformers
module Main
where
import Control.Monad.Error
data ConfiguredPackage = ConfiguredPackage
data FetchStepOutput = FetchStepOutput
data BuildStepOutput = BuildStepOutput
data BuildResult = BuildResult
@23Skidoo
23Skidoo / JSON.hs
Created October 17, 2011 23:09
More fun with Aeson
{-# LANGUAGE OverloadedStrings #-}
-- See
-- http://stackoverflow.com/questions/7800272/trying-to-parse-recursive-json-am-i-on-the-right-track/7800464
import Control.Applicative
import Control.Monad
import Data.Aeson
import Data.Attoparsec
import qualified Data.ByteString as B
@23Skidoo
23Skidoo / Indentation.hs
Created October 19, 2011 22:58
Indentation error
type Title = String
type Author = String
data Product = Book Title Author
| Video Author
| CD Title Integer Author
deriving (Eq,Show)
getTitle (Book title _ ) = title
getTitle (Video title ) = title
getTitle (CD title _ _ ) =title