Skip to content

Instantly share code, notes, and snippets.

module Main
( main
) where
import Data.Char
import Data.Set (Set)
import qualified Data.Set as S
import Control.Monad.Reader
import Control.Monad.IO.Class
Noise x >>= f = unsafePerformIO $ do
rand <- (randomIO :: IO Bool)
case rand of
True -> error "fuck"
False -> return $ f x
#include <iostream>
#include <stdexcept>
#include "match.hpp"
int main() {
int a, b, c;
zoid::match_tie(a, b, zoid::predicate<int, std::equal_to<int>>{42}, c) = std::make_tuple(1, 2, 42, 3);
std::cout << a << ", " << b << ", " << c << std::endl;
try {
daknok% valgrind ./a.out ~/Desktop
==11847== Memcheck, a memory error detector
==11847== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==11847== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==11847== Command: ./a.out
==11847==
==11847== WARNING: Support on MacOS 10.8 is experimental and mostly broken.
==11847== WARNING: Expect incorrect results, assertions and crashes.
==11847== WARNING: In particular, Memcheck on 32-bit programs will fail to
==11847== WARNING: detect any errors associated with heap-allocated data.
class Maybe
bind: (f) ->
if @_value is undefined then Nothing else f(@_value)
ret: (x) -> Just(x)
fmap: (f) ->
if @_value is undefined then Nothing else Just(f(@_value))
Just = (x) ->
+-------------+-----------------------------+
| God tier | Functional programming |
+-------------+-----------------------------+
| Top tier | Logic programming |
+-------------+-----------------------------+
| Middle tier | Imperative programming |
+-------------+-----------------------------+
| Shit tier | Object-oriented programming |
+-------------+-----------------------------+
| Shit crap | PHP |
foo() ->
Object = spawn(?MODULE, bar, [42]),
Object ! {add, 42},
Object ! {get, self()},
receive
Num -> io:printf("~s~n", [Num]) % prints 84
end.
bar(Num) ->
module Coroutine
( Coroutine(..)
) where
import Prelude hiding (id, (.))
import Control.Applicative
import Control.Arrow
import Control.Category
newtype Coroutine i o = Coroutine { runC :: i -> (o, Coroutine i o) }
class FunctorIO f where
fmapIO :: f a -> IO (f b)
data Input = Input Time Random Keyboard Mouse Joystick
data State = State {shizzle}
data Output = Output
data Game a = Game State a
instance FunctorIO Game where
map' :: (Int -> a -> b) -> [a] -> [b]
map' = map'' 0
where map'' :: Int -> (Int -> a -> b) -> [a] -> [b]
map'' _ _ [] = []
map'' i f (x:xs) = (f i x) : map'' (succ i) f xs