Skip to content

Instantly share code, notes, and snippets.

@TerrorJack
TerrorJack / gist:1f1cb2e6f9cd93a8bed0
Last active August 29, 2015 14:22
A simple concurrent crawler in Haskell.
{-# OPTIONS_GHC -Wall -O2 -threaded -with-rtsopts="-N" #-}
import Control.Concurrent
import Control.Concurrent.Async.Pool
import Data.ByteString.Lazy hiding (replicate)
import Network.HTTP.Client
import Network.HTTP.Client.TLS
getConcurrently :: [String] -> IO [ByteString]
getConcurrently urls = withManager tlsManagerSettings $ \mgr ->
@TerrorJack
TerrorJack / gist:f1c5e26dab474927c756
Last active August 29, 2015 14:23
Haskell blogs worth reading

Haskell blogs worth reading

This is a (hopefully) short list of Haskell blogs I consider worth reading for intermediate Haskellers.

* Technical choice: use HTML5.
*
* Portability to multiple platforms(resolutions) are great concerns
* Serve contents online (like Kancolle); opens potential for updating, user-login, and many more
* For traditional offline galgames, start a local server and use a browser
* Markup format for scripts
*
* Use XML markup for manuscripts; compile/dynamic load, reference HTML5 slides framework like impress.js
/*
* Copyright 1993-2015 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
@TerrorJack
TerrorJack / LazyVector.hpp
Last active January 5, 2016 02:45
Simple lazy vector in C++ which enables parallel evaluation.
#include <functional>
#include <vector>
template<typename T> using VectorIndex = typename std::vector<T>::size_type;
template<typename T>
class LazyVector {
public:
LazyVector();
@TerrorJack
TerrorJack / FreeState.hs
Last active March 4, 2016 05:22
A naive implementation of State Monad with Free Monad and left Kan extension.
{-# LANGUAGE DeriveFunctor, GADTs, StandaloneDeriving #-}
import Control.Monad.Free
data Lan g a where
Lan :: (b -> a) -> g b -> Lan g a
deriving instance Functor (Lan g)
data State s a where
@TerrorJack
TerrorJack / DList.hs
Last active March 30, 2016 14:19
Two different implementations for a same functional sequence with O(1) concat and O(n) fromList/toList.
newtype DList a = DList ([a] -> [a])
fromList :: [a] -> DList a
fromList l = DList (l++)
toList :: DList a -> [a]
toList (DList f) = f []
concat :: DList a -> DList a -> DList a
concat (DList lf) (DList rf) = DList $ lf . rf
@TerrorJack
TerrorJack / UTLC.hs
Created April 6, 2016 01:30
Untyped lambda calculus interpreter. Uses Higher Order Abstract Syntax, comes in call-by-value/call-by-name flavors (behaviors differ when interpreting test)
import Data.Functor
data Term = Lam (Term -> Term) | App Term Term
evalCBV :: Term -> IO Term
evalCBV t@(Lam _) = putStrLn "evalCBV: evaluating a WHNF, directly returned." $> t
evalCBV (App f x) = do
putStrLn "evalCBV: evaluating an application."
(Lam f') <- evalCBV f
x' <- evalCBV x
build/X86_MESI_Two_Level/gem5.opt configs/example/fs.py --kernel=x86_64-vmlinux-2.6.22.9-nolimit.smp --caches --l2cache --l1i_size=32kB --l1d_size=32kB --l1d_assoc=2 --l1i_assoc=2 --l2_size=128kB --l2_assoc=8 --script=/home/csa/Downloads/fft_4c.rcS --num-cpus=1 --num-dirs=4
@TerrorJack
TerrorJack / OpenSum.hs
Last active April 8, 2016 12:02
Typed open sum in Haskell, the naive approach.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
module Data.OpenSum where
import Data.Dynamic