Skip to content

Instantly share code, notes, and snippets.

@nurpax
nurpax / Exercises.hs
Created February 15, 2012 11:47
Haskell dojo
{-
Haskell exercises #1
- Factorial (duh!)
- Fibonacci
- Ackermann function
(Look any of these up from Wikipedia if you don't know them. That defines the spec. )
@nurpax
nurpax / cards_exercise.hs
Created February 16, 2012 11:03
Haskell dojo #1 homework
{-
Homework assignment for Haskell Dojo #1
---------------------------------------
1) Implement a function that takes as input a list of cards and
returns what poker hand it was.
You can see below for data type declarations that you can use for
representing the input and output of this function.
@nurpax
nurpax / DbIO.hs
Created February 20, 2012 08:51
Reader + IO monad transformer
import Control.Monad.Reader
data Db = Db { conn :: String }
type DbIO = ReaderT Db IO
insert :: String -> DbIO ()
insert s = do
conn <- asks conn
liftIO $ putStrLn ("Using connection " ++ conn ++ " inserting " ++ s)
@nurpax
nurpax / gist-emacs.md
Created June 26, 2012 20:55
gist test

Emacs gist test

gist-list - Lists your gists in a new buffer. Use arrow keys to browse, RET to open one in the other buffer.

gist-region - Copies Gist URL into the kill ring. With a prefix argument, makes a private gist.

gist-region-private - Explicitly create a private gist.

import Data.Either
import Database.SQLite
{-
SCHEMA
CREATE TABLE test (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(32)
commit 9d18e815c739ff6065349d5f10adf458a844406b
Author: Janne Hellsten <jjhellst@gmail.com>
Date: Thu Aug 16 09:17:58 2012 +0300
Throw an error if # of bind params doesn't the query (#2)
Fail with an error rather than let sqlite convert missing
parameters to NULLs.
diff --git a/Database/SQLite3.hsc b/Database/SQLite3.hsc

Compiling direct-sqlite 2.2 on Windows

Many Windows 7 hosts with only Haskell Platform do not have a C compiler installed. This makes it painful to install direct-sqlite as it compiles sqlite3.c as part of its build.

Here's how to install this package so that it links against a prebuilt sqlite3.dll:

$ cabal install direct-sqlite -fsystemlib --extra-include-dirs=/c/Users/$USER/include \
 --extra-lib-dirs=/c/Users/$USER/bin
@nurpax
nurpax / gist:6840820
Last active December 24, 2015 18:09
unsigned int to float
#include <stdio.h>
static inline float uintToFloat(unsigned int v)
{
union {
unsigned int ui;
float f;
} c;
c.ui = v;
return c.f;
@nurpax
nurpax / Test.hs
Last active August 29, 2015 13:56
cabal sandbox example
import qualified Data.Text as T
main :: IO ()
main = putStrLn (T.unpack . T.pack $ "hello")
@nurpax
nurpax / Test.hs
Created April 15, 2014 22:40
proof that Control.Lens rules
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
data A = A {
_aId :: Int
, _bs :: [B]
} deriving (Show)
data B = B {