Skip to content

Instantly share code, notes, and snippets.

@erantapaa
erantapaa / Main.hs
Created November 30, 2014 01:31
Using StateT with Haskeline
-- A receipe for using StateT with haskeline's InputT transformer.
-- Derived from this /r/haskell post: http://www.reddit.com/r/haskell/comments/1os0yq/haskeline_woes/
--
-- The key is using Control.Monad.State.Strict - using .Lazy doesn't work.
import Control.Monad.State.Strict
import Control.Monad.Trans (lift)
import System.Console.Haskeline
@erantapaa
erantapaa / gist:69fa2c060f67d74e477a
Created December 15, 2014 16:28
Timing subsequencesOfSize
import System.TimeIt
import System.Environment
import Text.Printf
subsequencesOfSize1 :: Int -> [a] -> [[a]]
subsequencesOfSize1 n xs = let l = length xs
in if n>l then [] else subsequencesBySize xs !! (l-n)
where
subsequencesBySize [] = [[[]]]
subsequencesBySize (x:xs) = let next = subsequencesBySize xs
@erantapaa
erantapaa / gist:82b59282dee72347efc2
Last active August 29, 2015 14:11
building gtk 2.x on OSX for Haskell

Check list for installing gtk 2.x for Haskell on OSX:

  1. Install XQuartz (link) - this is needed for the xcb-shm package config file.
  2. brew install gtk+
  3. export PKG_CONFIG_PATH=/usr/local/Cellar/cairo/(...whatever...)/lib/pkgconfig:/opt/X11/lib/pkgconfig/:
  4. Make sure alex and happy are installed - they are needed by gtk2hs-buildtools
  5. cabal install gtk2hs-buildtools
  6. cabal install gtk
@erantapaa
erantapaa / p8.hs
Created January 14, 2015 05:37
implementing sequencePipes
import System.Environment
import qualified Data.Array as A
import Data.Array.IO
import qualified Data.Array.MArray as M
import Data.Array.Base ( UArray, unsafeFreezeSTUArray )
import Data.Array.Unboxed
import qualified Data.Array.Unboxed as U
import Control.Monad
import Debug.Trace
import Pipes
@erantapaa
erantapaa / e14.hs
Created January 15, 2015 04:05
euler #14 collatz problem
{-# LANGUAGE BangPatterns #-}
import Data.Array.IO
import Data.Array.Unboxed
import Control.Monad
collatz x
| even x = div x 2
| otherwise = 3*x+1
@erantapaa
erantapaa / gauss.hs
Created January 17, 2015 03:47
solution to 1had "Let it snow" http://lpaste.net/118571
-- Solution to "Let it snow" 1had - http://lpaste.net/118571
import qualified Data.Map.Strict as M
import Data.List
import Control.Monad
import Data.Maybe
data SnowFlake = Six | Star | Eight | Flower | Unit
deriving (Eq, Ord, Show)
@erantapaa
erantapaa / nested.x
Created January 26, 2015 02:09
alex nested comment example
{
module Nested where
import Control.Monad
}
%wrapper "monadUserState"
$whitespace = [\ \t\b]
$digit = 0-9 -- digits
@erantapaa
erantapaa / example.hs
Created January 27, 2015 18:14
embed svg diagram in html using blaze
{-# LANGUAGE OverloadedStrings #-}
import Text.Blaze.Svg11 ((!), mkPath, rotate, l, m)
import qualified Text.Blaze.Svg11 as S
import qualified Text.Blaze.Svg11.Attributes as A
import Text.Blaze.Svg.Renderer.String (renderSvg)
import qualified Text.Blaze.Html5 as H
import Text.Blaze.Html.Renderer.Text
import qualified Data.Text.Lazy.IO as TL
main :: IO ()
@erantapaa
erantapaa / cabal.config
Created February 2, 2015 20:10
hackage versions as of 2012-05-23 UTC
-- Hackage versions as of 2012-05-23 00:00:00 UTC
constraints:
4Blocks <= 0.2,
AC-Angle <= 1.0,
AC-Boolean <= 1.1.0,
AC-BuildPlatform <= 1.1.0,
AC-Colour <= 1.1.4,
AC-EasyRaster-GTK <= 1.1.3,
AC-HalfInteger <= 1.2.1,
AC-MiniTest <= 1.1.1,
#!/bin/sh
#
# Recipe for reproducing a linkage error with GHC 7.8.3 under OSX.
#
# GHC was installed using https://ghcformacosx.github.io/
#
# Specific 7.8.3 version: https://github.com/ghcformacosx/ghc-dot-app/releases/download/v7.8.3-r1/ghc-7.8.3-r1.zip
#
# Output of the find command at the end will include a reference to 'findExecutable3_info',
# but nowhere does the tar package reference the function 'findExecutable'.