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
sealed trait Interact[A] | |
case class Ask(prompt: String) | |
extends Interact[String] | |
case class Tell(msg: String) | |
extends Interact[Unit] | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] |
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
// Illustrate disciplined C++ code | |
// http://www.cplusplus.com/reference/vector/vector/ | |
#include <vector> | |
#include <iostream> | |
using namespace std; | |
class Foo { | |
public: |
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 Test.HUnit | |
import qualified Data.List as List | |
import qualified Data.Ord as Ord | |
import Data.PSQueue as PSQueue | |
{- | |
For @BillLaboon | |
hey @franklinchen is there an easy way in Haskell to find out which element in a list is most common, e.g. [1,1,1,2,3] -> 1 ? |
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
require 'minitest/autorun' | |
# Traverse in preorder | |
def tree_traverse(tree, &block) | |
if tree.is_a? Array and tree.length > 0 | |
yield tree | |
tree.each {|t| tree_traverse(t, &block) } | |
end | |
end | |
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 qualified System | |
import qualified Data.List as List | |
import qualified Data.Char as Char | |
import qualified Data.HashMap.Strict as HashMap | |
main :: IO () | |
main = do | |
[arg] <- System.getArgs | |
text <- getContents | |
let n = read arg |
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
#include <stdlib.h> | |
#include <stdio.h> | |
/* Single inheritance, treating Animal as abstract base class. */ | |
typedef struct Animal_vtable { | |
void (*eat)(void *); | |
void (*sound)(void *); | |
} Animal_vtable; | |
typedef struct Animal { |
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
// C++ abuse | |
#include <iostream> | |
using namespace std; | |
class Animal { | |
public: | |
virtual void food() = 0; | |
virtual void sound() = 0; |
NewerOlder