Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE ExistentialQuantification #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-unused-do-bind -fno-warn-unused-imports -fno-warn-orphans #-}
module Main where
import Control.Applicative
import Data.List (foldl')
import Data.Monoid
import Data.Strict.Tuple
import Prelude hiding (sum, length)
module Main where
import Control.Concurrent hiding (yield)
import Control.Concurrent.Chan
import Data.Char (chr)
import Data.Maybe
import Control.Monad
import Control.Monad.Random ( RandomGen, Rand, getRandomR, evalRandIO)
import Control.Monad.Trans.State.Strict (StateT, get, put, evalStateT)
import Data.List
@tonyday567
tonyday567 / emitter.hs
Last active December 22, 2015 04:48
emitter random walk plus stop/go effect
{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-unused-do-bind -fno-warn-unused-imports -fno-warn-orphans #-}
--
-- Random walk emitter with go and stop button
--
module Main where
import Control.Applicative
@tonyday567
tonyday567 / example.hs
Created November 20, 2013 06:01
Edge vs ListT
{-# LANGUAGE Arrows #-}
import Prelude hiding ((.), id)
import Control.Arrow (Arrow(arr, first), ArrowChoice(left))
import Control.Category (Category((.), id))
import Control.Foldl
import Control.Monad ((>=>))
import Control.Monad.Trans.State.Strict (get, put)
import Pipes
bird
----
> {-# LANGUAGE GADTs, TypeSynonymInstances #-}
> module ArcChallenge where
>
> import Control.Applicative
> import Control.Applicative.Error (Failing (..))
> import Control.Monad (ap)
In this gist we will first show that we can beat the arc challenge
(http://www.paulgraham.com/arcchallenge.html), and then build the library that
shows how we did it. This gist is Literate Haskell and is of course executable. The packages needed are happstack-server and applicative-extras, installable using cabal.
Let's start with some imports (for now, you can ignore these)
> {-# LANGUAGE GADTs, TypeSynonymInstances #-}
> module ArcChallenge where
>
> import Control.Applicative
literate haskell test
> {-# LANGUAGE RankNTypes, KindSignatures #-}
> module ArcChallenge where
>
> import Control.Applicative
> module ArcChallenge where
>
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
{-# LANGUAGE ExistentialQuantification, RankNTypes #-}
module Scanl where
import Control.Foldl (Fold(..))
import Data.Foldable (Foldable)
import qualified Data.Foldable as F
import Data.Traversable
scan :: (Foldable f) => Fold a b -> f a -> [b]
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DefaultSignatures #-}
import GHC.Generics
import Control.Applicative
import Data.Text.Encoding
import Data.Aeson
import Data.Aeson.Types
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as LB