Skip to content

Instantly share code, notes, and snippets.

cdepillabout / rank2types-example.hs
Created Oct 28, 2014
short example of a place where rank2types and rankntypes are necessary
View rank2types-example.hs
{-# 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 / comb.hs
Last active Aug 29, 2015
explanation of combination function in Haskell
View comb.hs
{-# LANGUAGE ScopedTypeVariables #-}
-- | This is an explanation of a combination function written in Haskell
-- from
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 / .gitignore
Last active Aug 29, 2015
notes on some of the difficult concepts used in servant (to be expanded into blog post)
View .gitignore
cdepillabout / example.hs
Last active Aug 29, 2015
sample for using stack to make a .hs executable and run it from the command line
View example.hs
#!/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).
cdepillabout / MonitorDirectory.hs
Created Oct 7, 2013
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.
View MonitorDirectory.hs
#!/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 / small-lens-example.hs
Last active Aug 3, 2017
small example of using lens
View small-lens-example.hs
#!/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 / lens-from-scratch.hs
Created Aug 4, 2017
Example of creating lenses in Haskell from scratch.
View lens-from-scratch.hs
{-# 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 / example.hs
Last active Aug 25, 2017
non-lawful Monoid instances for building up AST considered not harmful in Haskell?
View example.hs
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- This is a gist for the stackoverflow question
cdepillabout / doubly-linked-list.hs
Created Feb 9, 2018
Doubly-linked list in Haskell, using MVars
View doubly-linked-list.hs
{-# LANGUAGE NamedFieldPuns #-}
-- This is similar to
module Main where
import Control.Concurrent.MVar
import Control.Monad
import Data.List.NonEmpty