This file contains hidden or 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.Word8 | |
import Data.Bits | |
import Data.Char | |
import Data.List | |
-- Sample text taken from Wikipedia | |
sampleText :: String | |
sampleText = "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" | |
-- splitEvery is defined in the Data.List.Splits library from package |
This file contains hidden or 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
# Threw together these two functions to demonstrate adding some immutable modification | |
# functions to Ruby's Array class. "update" takes a hash of indices to values and | |
# returns a new array with the appropriate indices replaced by the supplied values. | |
# "modify" takes a list of indices and runs the block on those indices that match; | |
# like a version of "map" where you can specify the indices. | |
# Maybe you can already do this in Ruby, but I couldn't see anything in the docs so | |
# here's my hacky little monkey patch... | |
class Array |
This file contains hidden or 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 Foundation | |
//Dumb protocols... because protocols can't (afaik) take a generic type | |
//parameter, I can't define functions like fmap and bind in them, which are | |
//pretty essential for any kind of Functor/Monad implementation, but there you | |
//go... | |
//The bits in comments demonstrate what I'd *like* to do... | |
protocol Functor { | |
typealias WrappedType | |
typealias SelfGeneric |
This file contains hidden or 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 RecursiveDo #-} | |
{-# LANGUAGE PatternSynonyms #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
import Prelude hiding (print, and, or) | |
import Data.Bits hiding (xor, bit) | |
import Data.Word |
This file contains hidden or 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
// Tested with clang version: Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) | |
// clang++ --std=c++11 enum-classes.cpp | |
#include <iostream> | |
#include <cassert> | |
#include <array> | |
enum class MaleNames { | |
JACK, | |
JOHN, |
OlderNewer