There are lots of representations for strings. In most languages they pick one set of tradeoffs and run with it. In haskell the "default" implementation (at least the one in the prelude) is a pretty bad choice, but unlike most other languages (really) good implementations exist for pretty much every way you can twist these things. This can be a good thing, but it also leads to confusion, and frustration to find the right types and how to convert them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type z | |
type 'a s | |
(* Sadly enough, without kind restrictions, this still allows nonsense types like *) | |
type nonsense = int s | |
(* GHC 7.6 supports this (lifting types to kinds & kind constraints) ;-) *) | |
type (_, _) llist = | |
| Nil : (z, 'a) llist | |
| Cons : ('a * ('l, 'a) llist) -> ('l s, 'a) llist |
Have you ever had to write code that made a complex series of succesive modifications to a single piece of mutable state? (Almost certainly yes.)
Did you ever wish you could make the compiler tell you if a particular operation on the state was illegal at a given point in the modifications? (If you're a fan of static typing, probably yes.)
If that's the case, the indexed state monad can help!
Motivation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection._ | |
import scala.collection.mutable.{ArrayBuffer,ListBuffer, Builder} | |
import scala.collection.generic._ | |
import scala.collection.immutable.VectorBuilder | |
// ================================ CustomTraversable ================================== | |
object CustomTraversable extends TraversableFactory[CustomTraversable] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings, RankNTypes, KindSignatures, FlexibleContexts #-} | |
module Plugins.NotificationDaemon where | |
-- xmobar plugin API | |
import Plugins | |
import DBus.Bus | |
import DBus.Client | |
import DBus.Constants |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE NoMonomorphismRestriction, ViewPatterns #-} | |
import XMonad | |
import System.Exit | |
import Control.Monad | |
import Control.Concurrent | |
import Control.Arrow (second) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
swap :: Int -> Int -> [a] -> [a] | |
swap i j xs | i == j = xs | |
swap i j xs | otherwise = initial ++ (xs !! b) : middle ++ (xs !! a) : end | |
where [a,b] = sort [i,j] | |
initial = take a xs | |
middle = take (b-a-1) (drop (a+1) xs) | |
end = drop (b+1) xs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def coroutine(func): | |
""" | |
A decorator that turns a function with normal input into a coroutine. | |
This decorator takes care of priming the coroutine, doing the looping and | |
handling the closing. | |
The first argument of any decorated function is what was received when | |
data was sent to the coroutine via the ``.send`` method. All the other | |
``*args`` and ``**kwargs`` are what was passed to the decorated function | |
when instantiating the coroutine. |
Tired of waiting for emacs to start on OS X? This step by step guide will
teach you how to install the latest version of emacs and configure it to start
in the background (daemon mode) and use emacsclient
as your main editor.
Download the latest pretest version of [Emacs for Mac OS X]: http://emacsformacosx.com/builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 0 is too far from ` ;) | |
set -g base-index 1 | |
# Automatically set window title | |
set-window-option -g automatic-rename on | |
set-option -g set-titles on | |
#set -g default-terminal screen-256color | |
set -g status-keys vi | |
set -g history-limit 10000 |