Skip to content

Instantly share code, notes, and snippets.

@cdepillabout
cdepillabout / MonitorDirectory.hs
Created October 7, 2013 11:36
This is a program that will recursively monitor a directory for changed files. When it detects a changed file, it will use scp to upload that file to a server. This is nice for being able to edit files on your local computer and have them automatically synced to a remove computer as soon as you :w them in vim.
#!/usr/bin/env runhaskell -Wall
import Control.Concurrent (threadDelay, forkIO)
import Control.Concurrent.MVar
import Control.Monad (liftM, filterM)
import Data.List (isPrefixOf, (\\))
import HSH.ShellEquivs (glob)
import System.Directory (canonicalizePath, getCurrentDirectory, doesFileExist)
--import System.Environment (getArgs)
import System.FilePath ((</>))
@cdepillabout
cdepillabout / rank2types-example.hs
Created October 28, 2014 15:41
short example of a place where rank2types and rankntypes are necessary
{-# LANGUAGE Rank2Types #-}
-- This is a small example of where you need to use Rank2Types (or
-- RankNTypes).
-- The 'a' type is being used polymorphically here, but when it
-- is called, it will already be bound (as either an Int or String),
-- so it cannot be used polymorphically.
--
@cdepillabout
cdepillabout / comb.hs
Last active August 29, 2015 14:21
explanation of combination function in Haskell
{-# LANGUAGE ScopedTypeVariables #-}
-- | This is an explanation of a combination function written in Haskell
-- from http://rosettacode.org/wiki/Combinations#Dynamic_Programming_2
module Main where
-- | Adds a @a@ to the beginning of every list inside the list of lists.
-- However, if the list of lists is just an empty list, return an empty
-- list.
@cdepillabout
cdepillabout / .gitignore
Last active August 29, 2015 14:23
notes on some of the difficult concepts used in servant (to be expanded into blog post)
dist
cabal-dev
*.o
*.hi
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
@cdepillabout
cdepillabout / example.hs
Last active August 29, 2015 14:24
sample for using stack to make a .hs executable and run it from the command line
#!/usr/bin/env stack
-- stack --resolver=nightly-2015-07-08 runghc --package=shelly
-- The ExtendedDefaultRules extension gives us an experience similar to
-- @ghci@. Raw values (1 and 10 below) that implement the 'Num' type
-- class will be defaulted to 'Int' (specified with the @default@
-- command below). Raw values (all strings) that implement the
-- 'IsString' typeclass will be defaulted to Text (also specified
-- with the @default@ command below).
--

Haskell DB Library Comparison

We will be comparing the following DB libraries:

  • HRR
  • Opaleye
  • Persistent + Esqueleto
  • Groundhog
  • postgresql-simple (and postgresql-transactional)
@cdepillabout
cdepillabout / small-lens-example.hs
Last active August 3, 2017 17:07
small example of using lens
#!/usr/bin/env stack
-- stack --resolver lts-9.0 script --package transformers --package lens -- -Wall
-- If you have stack installed, all you need to do is make this file executable
-- and you can run it from the command line.
module Main where
import Control.Lens (Prism', Traversal', _1, _2, preview, prism', set)
@cdepillabout
cdepillabout / lens-from-scratch.hs
Created August 4, 2017 13:17
Example of creating lenses in Haskell from scratch.
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE RankNTypes #-}
module Main where
import Data.Functor.Identity (Identity(Identity, runIdentity))
type Lens s a = forall f. Functor f => (a -> f a) -> s -> f s
data UserName = UserName { first :: String, second :: String } deriving Show
@cdepillabout
cdepillabout / example.hs
Last active August 25, 2017 15:29
non-lawful Monoid instances for building up AST considered not harmful in Haskell?
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
------------------------------------------------------
-- This is a gist for the stackoverflow question
-- https://stackoverflow.com/questions/45884762/non-lawful-monoid-instances-for-building-up-ast-considered-not-harmful-in-haskel
------------------------------------------------------