Skip to content

Instantly share code, notes, and snippets.

@qpliu
qpliu / gist:3259111
Created August 4, 2012 18:14
Half-baked proposal: Error-return statement for Go (golang)

Half-baked proposal: Error-return statement for Go (golang)

Code in Go that propagates errors can get pretty verbose. For example:

    a, err := ...
    if err != nil {
            return nil, err
    }

b, err := ...

@qpliu
qpliu / DCPU16.hs
Created April 6, 2012 04:45
Implementation of version 1.1 of http://0x10c.com/doc/dcpu-16.txt
-- Implementation of version 1.1 of http://0x10c.com/doc/dcpu-16.txt.
-- This work is public domain.
module DCPU16 where
import Control.Monad(foldM)
import Data.Array.IO(IOArray)
import Data.Array.MArray(newListArray,readArray,writeArray)
import Data.Bits((.&.),(.|.),shiftL,shiftR,xor)
import Data.Ix(Ix)
import Data.Word(Word16,Word32)
@qpliu
qpliu / gist:875594
Created March 18, 2011 03:50
Exploring lists as instances of MonadPlus in Haskell by implementing filter
> import Control.Monad(MonadPlus(mzero),liftM,unless)
The regular filter can be implemented recursively:
> f1 _ [] = []
> f1 test (a:as) | test a = a : f1 test as | otherwise = f1 test as
Or the recursion can be abstracted:
> f2 test list = foldr (\ a rest -> if test a then a : rest else rest) [] list