Skip to content

Instantly share code, notes, and snippets.

View bitemyapp's full-sized avatar
🐺
aroo

Chris A. bitemyapp

🐺
aroo
View GitHub Profile
@maurisvh
maurisvh / fcast.hs
Last active January 20, 2017 00:32
tiny terminal livestreaming server
-- to watch: telnet localhost 8887
-- to stream: script -f >( (echo hello streamname; cat -) | nc -q5 localhost 8888 > /dev/tty )
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Concurrent
import Control.Concurrent.Chan
import Control.Concurrent.MVar
import Control.Monad
@paf31
paf31 / Arbiter.hs
Last active August 29, 2015 14:11
needs a better name
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
module Main where
import Test.QuickCheck
class Arbiter f r where
arbiter :: f -> Gen r
instance Arbiter r r where
@andrewthad
andrewthad / natural_join.hs
Created December 19, 2014 00:21
Haskell implementation of relational algebra's natural join
{-# LANGUAGE GADTs, DataKinds, KindSignatures, TypeOperators, TypeFamilies,
MultiParamTypeClasses, FlexibleInstances, PolyKinds, FlexibleContexts,
UndecidableInstances, ConstraintKinds, OverlappingInstances, ScopedTypeVariables #-}
import GHC.TypeLits
import Data.Type.Bool
import Data.Type.Equality
import Data.Proxy
import Control.Applicative ((<$>), (<*>))
import Data.Maybe (catMaybes)
@aaronlevin
aaronlevin / haskell-project.nix
Last active August 29, 2015 14:13
Nix n00b templates
# This template will give you a prompt with:
# - ghc
# - cabal
# - ghc-mod
# - the libraries: free, mtl, transformers
#
# to run: nix-shell haskell-project.nix
#
# to specify specific version of haskell, you can:
# nix-shell --arg haskellPackages 'with import <nixpkgs> {}; haskellPackages_ghc783_profiling'
@nkpart
nkpart / fmap.md
Last active December 5, 2024 05:31
fmap . fmap . fmap

fmap . fmap . fmap

Functors and Traversables compose.

You might have seen this statement before. This is how you can take advantage of it.

Composing many fmap calls gives you a function that will drill down into a structure and modify it at a certain depth in that nested structure.

@jozefg
jozefg / queue.idr
Last active August 29, 2015 14:14
Queue in Idris
module queue
import Data.Vect
-- Here's the port of the Liquid Haskell blog post on amortized
-- queues. The tricksy bit is that the "amortized" bit depends on
-- laziness. This means that while in the REPL (where Idris is lazy)
-- this is reasonably efficient. It compiles absolutely horribly
-- though because each time push or pop something we rotate the whole
-- damned thing.
@nkpart
nkpart / Err.hs
Last active August 20, 2022 01:20
Lens, Prisms, and Errors.
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fwarn-missing-methods #-}
module Err where
import Control.Lens
import Control.Monad.Error
import Control.Monad.Error.Lens
-- Here is a fairly typical situation, where we have low level errors in certain
@tonymorris
tonymorris / functor.hs
Created February 9, 2015 01:44
Higher-kinds and type-classes are distinct concepts.
{-# LANGUAGE RankNTypes #-}
module Functor where
import Prelude(
foldr
, (.)
, Maybe(Nothing, Just)
, maybe
)
@tonymorris
tonymorris / condenscension-police.md
Last active August 29, 2015 14:15
The Condenscension Police

CAUTION: this rant has not been proof-read to any extent at all

The condenscension police are here, with their double-standards and unquestionable claim to a moral high-ground. Persistently engaged in disgusting conduct, I ask, "do they ever look at themselves?"

I know the answer to this question. I tested it. At one point in time, I was concerned that the charge directed at me had merit. Were they right? Were they a bit wrong, but mostly right? I wanted to know the answer to this question. No, I really really wanted to know it. So I invested some effort toward answering

@chrisdotcode
chrisdotcode / Promise.hs
Created February 16, 2015 00:07
Abstract Promises in Haskell
module Promise where
import Control.Applicative (Applicative(..))
import Data.Monoid (Monoid(..))
newtype Error = Error { unString :: String } deriving (Eq, Ord, Read, Show)
data Promise a = Failed Error | Deferred | Fulfilled a
deriving (Eq, Ord, Read, Show)