Skip to content

Instantly share code, notes, and snippets.

View dimitri-xyz's full-sized avatar

Dimitri DeFigueiredo dimitri-xyz

View GitHub Profile
@dimitri-xyz
dimitri-xyz / merging2.hs
Last active October 13, 2015 19:36
Merging 2 branches - function definition depends on constant definition
-- base
-------
c :: Int
c = 5
plusc :: Int -> Int
plusc x = x + c
main = putStrLn $ "the total is: " ++ show (plusc 1)
@dimitri-xyz
dimitri-xyz / merging.hs
Last active October 13, 2015 19:38
Merging 2 branches - function definition does NOT depend on constant
-- base
-------
c :: Int
c = 5
plusone :: Int -> Int
plusone x = x + 1
main = putStrLn $ "the total is: " ++ show (plusone c)
-----------------------------------
import System.IO
import Control.Monad.Reader
import Control.Monad.IO.Class
import Control.Exception.Base (evaluate)
data ColumnHeaders = FirstLine | None
withCSV :: FilePath -> (Handle -> IO r) -> IO r
withCSV path action = do
import System.IO
import Control.Monad
import Control.Monad.IO.Class
import Control.Exception.Base (evaluate)
import Pipes
import Pipes.Prelude (stdoutLn)
withCSV :: FilePath -> (Handle -> IO r) -> IO r
withCSV path action = do
@dimitri-xyz
dimitri-xyz / RejectionSampling.hs
Created April 20, 2017 01:14
A non-biased way to generate random integers in a given range
import Control.Monad.Random.Class
import System.Random
import Data.Word
maxIterations :: Int
maxIterations = 100
acceptReject :: (Random a, MonadRandom m) => (a -> Bool) -> (a -> b) -> m b
acceptReject = acceptReject' (Just maxIterations)