Skip to content

Instantly share code, notes, and snippets.

View igstan's full-sized avatar

Ionuț G. Stan igstan

View GitHub Profile
@travisbrown
travisbrown / kata-bank-ocr.scala
Created September 21, 2012 18:09
KataBankOCR checksum at the type level
/**
* We can use the Scala type system (with help from Miles Sabin's Shapeless
* library) to solve the bank account number validation problem in the second
* user story of the KataBankOCR kata on Coding Dojo:
*
* http://codingdojo.org/cgi-bin/wiki.pl?KataBankOCR
*
* By Travis Brown in response to a question by Paul Snively on the Shapeless
* Dev mailing list:
*
@snoyberg
snoyberg / overloaded-lists.md
Created September 21, 2012 12:42
Overloaded lists proposal

Many of us use the OverloadedStrings language extension on a regular basis. It provides the ability to keep the ease-of-use of string literal syntax, while getting the performance and correctness advantages of specialized datatypes like ByteString and Text. I think we can get the same kind of benefit by allowing another literal syntax to be overloaded, namely lists.

Overly simple approach

The simplest example I can think of is allowing easier usage of Vector:

[1, 2, 3] :: Vector Int

In order to allow this, we could use a typeclass approach similar to how OverloadedStrings works:

@gregorycollins
gregorycollins / bench.hs
Created September 20, 2012 16:19 — forked from snoyberg/bench.hs
Lower-casing a ByteString
{-# LANGUAGE OverloadedStrings, MagicHash, UnboxedTuples, BangPatterns #-}
import Control.Monad (replicateM_)
import Criterion.Main (defaultMain, bench, whnfIO)
import qualified Data.ByteString as S
import qualified Data.ByteString.Char8 as S8
import Data.ByteString.Unsafe (unsafePackAddressLen, unsafeUseAsCStringLen)
import qualified Data.Char
import Data.Char (ord)
import qualified Data.Word8
@sebastiaanvisser
sebastiaanvisser / g0.hs
Created September 10, 2012 08:07
Composing algebras.
{-# LANGUAGE
GADTs
, KindSignatures
, RankNTypes
, TupleSections
, TypeOperators
#-}
module Generics.Morphism where
import Control.Arrow
@tonymorris
tonymorris / ListZipper.scala
Created August 29, 2012 01:15
List Zipper
case class ListZipper[+A](lefts: List[A], x: A, rights: List[A]) {
def map[B](f: A => B): ListZipper[B] =
sys.error("todo")
// map with zipper context
def coFlatMap[B](f: ListZipper[A] => B): ListZipper[B] =
sys.error("todo")
def findRight(p: A => Boolean): Option[ListZipper[A]] =
sys.error("todo")
@manuel
manuel / representing-monads.scm
Created August 28, 2012 00:08
Error monad from Filinski's "Representing Monads"
;; Error monad from Filinski's "Representing Monads"
(define *default-prompt* (make-prompt))
(define (reflect m) (shift *default-prompt* k (ext k m)))
(define (reify t) (push-prompt *default-prompt* (unit (t))))
(define-record-type Success
(make-success a)
success?
@coreyhaines
coreyhaines / A Description of Rules
Created August 15, 2012 03:45
100 x 100 Game of Life Kata
Write a system that evolves a 100 x 100 grid of cells
to the next generation according to the following rules.
1) Any living cell with less than 2 live neighbors dies
2) Any living cell with 2 or 3 live neighbors stays alive
3) Any living cell with more than 3 live neighbors dies
4) Any dead cell with exactly 3 lives neighbors comes to life
Note: A cell has 8 neighbors
...
@coreyhaines
coreyhaines / Tests
Created August 15, 2012 03:33
Number 2 LED
Create a system that will convert a numeric value to an 3x5 LED display.
...
...
...
...
...
Feature: Generating LCD representation for single numbers
@tonyg
tonyg / mtl.rkt
Created August 8, 2012 13:46
Multitasking with Continuations and Lists
#lang racket/base
(define tasklist (list (list 'root (box 'no-continuation))))
(define currtask tasklist)
(define call/cc call-with-current-continuation)
(define fork
(lambda (name)
(call/cc
@swannodette
swannodette / gist:3217582
Created July 31, 2012 14:52
sudoku_compact.clj
;; based on core.logic 0.8-alpha2 or core.logic master branch
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))