TAIM (Alpha Version): GHCI integration with vim
Overview
TAIM aims to couple either a local or remote ghci instance with vim. Similar to SLIME which does the same thing for emacs and common lisp. In short you can evaluate code in place, and receive feedback, without having to reload the whole buffer into ghci.
Dependencies
- Python 2.6
- Vim 7.2
- Haskell Platform
- Only tested on Linux so far
Current Usage
- Download taimReleaseAlpha.tar.gz
- Unpack it, and in the taimReleaseAlpha directory run cabal install
- Run the taimReleaseAlpha program, under ~/.cabal/bin/taimReleaseAlpha
- Open up vim and source taim.vim, or just install taim.vim as a plugin
- In vim :StartTaim which will split the window for you
- In command mode press<C-x><C-e> (Control+x followed by Control+e) to evaluate the line the cursor is currently at.
Screencast
Click the image below to see a video of it running. You will see :EvalCode at the bottom every time <C-x><C-e> is pressed:
TODOs
There is a ton left to do, some of the major ones being:- Evaluate functions that won't work directly in ghci (ie. without let)
- Handle imports
- Handle grouping functions via module
- Handle module renaming
- Severely clean up code
- Start taim.hs executable from taim.vim
- Handle type/class definitions
- Auto installer for vim script
- Test on Windows
- Fix scrolling issues on toggle of windows
- Consistent output flushing
- Configuration file to allow placement and size of output window, and network location of ghci session.
Conclusion
This is pretty basic right, but I've already been finding it pretty useful. It makes it alot easier to toy around in ghci right now, and can hopefully be expanded to be a pretty comprehensive development environment for Haskell.
Comments(2)
2010-06-06 16:06:31
Haskell Arduino Serial I/O
Overview
The Arduino is a popular electronics prototyping platform. It is easy to interface to a computer via a real or emulated (Through USB) serial connection. This write-up details how to communicate with the Arduino in Haskell.
Pre-requisites
- Arduino software installed and working.
- Haskell Platform installed with Serial package from Hackage(cabal install serial)
- A program with serial I/O loaded on the Arduino (The PhysicalPixel example that comes with arduino will work)
Send a simple command
import System.Serial import IO serialCommand :: String -> IO () serialCommand comm = do h <- openSerial "/dev/ttyUSB0" B9600 8 One NoParity Software hPutStr h comm
Serial Monitor
- serialMonitor.hs -- Code that acts like the Arduino serial monitor. Handles input and output of data.
Servo and LED Demo
Quick demo of running a servo motor and LED from Haskell using serialMonitor.hs. H turns on the light, L turns it off, the numbers 0-9 are the step to take (0-180) by 20 degree increments. The Arduino sends back a status after each command, saying either the state of the light, or the degree of the servo.
- serialServo.pde -- Arduino code used in this demo. Moves a servo between 0-180 degrees in 20 degree steps, and turns on a light
Video of serialMonitor.hs program running:
Comments(0)
2010-05-23 22:24:04
HDBC-mysql Example
Overview
HDBC-mysql is a way to talk to mysql using Haskell. Like alot of things in Hackage, there isn't alot of demo code, so here is how I've been using it. Besides the initial connection it provides the same functions/types as the rest of HDBC.
Database Setup
Requires the following MySQL setup:
CREATE DATABASE hdbcTest; GRANT ALL ON hdbcTest.* TO hdbc@'%' IDENTIFIED BY 'hdbc'; use hdbcTest; create table test ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), value varchar(255) );
/var/run/mysqld/mysqld.sock
Change as needed.
Haskell Connection
Simple connection and test:
import Control.Monad
import Database.HDBC
import Database.HDBC.MySQL
main = do
conn <- connectMySQL defaultMySQLConnectInfo {
mysqlHost = "localhost",
mysqlPort = 3306,
mysqlUnixSocket = "/var/run/mysqld/mysqld.sock",
mysqlDatabase = "hdbcTest",
mysqlUser = "hdbc",
mysqlPassword = "hdbc"
}
rows <- quickQuery' conn "SELECT 1 + 1" []
forM_ rows $ row -> putStrLn $ show row
Something a little more complicated. Grab the count of entries, insert that count, and then spit out all the values. After the connection is established (ie the bottom of the last example).
rows <- quickQuery' conn "SELECT count(*) from test" []
run conn ("insert into test (value) values" ++
countString rows) []
rows <- quickQuery' conn "SELECT value from test" []
forM_ rows $ row -> putStrLn $ sqlValue row
That increase each time the code is ran.
Full code of the second example is available here: mysqlTest.hs
Comments(0)
2010-04-03 02:24:09
CheaTorrent -- An evil BitTorrent client
Overview
This is the source tarball of a few simple tweaks to ctorrent. It requires knowledge of how to compile programs and run them from the command line. The people tech savvy enough to use this are likely able to falsify their ratios anyway.
With that said, this bitorrent client has an 'evil' set of defaults. It will not upload to peers, reports back that it has uploaded ~70% of what it has downloaded, immediately closes once downloading is complete, and spoofs it's user agent to a known popular client. This is the default behaviour, although some of it can be changed on the command line
There are three reasons I made this:
- Show that upload stats are worthless for determining level of infringement. They can be set by the users themselves.
- Show that private trackers are relying on obscurity to ensure people have good ratios. The underlying mechanism used is flawed.
- Many private trackers have ridiculous ratio requirements. This side steps that issue.
Screenshot

Downloads
cheatorrent_v1.0.tar.gz -- Tarball of source code, with configure scriptConclusion
I didn't change any of the command line options, but would if there was any interest. Also I may, one of these years, add the capability to falsify reported download.
Comments(2)
2010-03-14 23:48:04
Collatz Conjecture in Haskell
Overview
The Collatz Conjecture is based on sequences from the following formulas:
n/2 for even n 3*n + 1 for odd n
Collatz Sequence Code
Code to generate sequences and find the lengths of the sequences:
test :: Int -> Int
test x | even x = x `div` 2
| otherwise = 3*x + 1
collatz :: Int -> [Int]
collatz 1 = [1]
collatz x = x : collatz (test x)
numCollatz = map (length . collatz) [1..]
Output Code
Generates a table that gnuplot can handle.
format x y = show x ++ "t" ++ show y table x = unlines (zipWith format [1..] (take x numCollatz)) main = writeFile "collatz.dat" (table 100000)
Images
1000, 10000, and 100000 numbers respectively



Video
Click the image below for a video of the behavior as we go to higher numbers (Pretty obvious from the above pictures :p).

Code
- collatz.hs --Haskell code described above
- collatz.gnu -- The gnuplot code to generate a graph
Comments(0)
2010-02-28 23:24:35
Recent Activity
- TAIM (Alpha Version): GHCI integration with vim
- Haskell Arduino Serial I/O
- HDBC-mysql Example
- CheaTorrent -- An evil BitTorrent client
- Collatz Conjecture in Haskell
- Continuous Inking System (Epson R300)
- Streamed web images without flickering
- Self Modifying 2D Turing Automata
- Competing Conway Life Automata
- X11 Timelapse Desktop Video
Recent Comments
- Gavin Black (TAIM (Alpha Version): GHCI integration with vim)
- Jay (TAIM (Alpha Version): GHCI integration with vim)
- Brent Fisher (Image to Spectrogram)
- Gavin Black (Nontransitive Dice Finder)
- J. Siehler (Nontransitive Dice Finder)
- J. Siehler (Nontransitive Dice Finder)
- John Boreiko (E-Mail)
- Stine (CheaTorrent -- An evil BitTorrent client)
- Stine (CheaTorrent -- An evil BitTorrent client)
- Gavin Black (Nontransitive Dice Finder)