twitterからながれてきたこの話題。昔のCコンパイラは、if文の条件節で代入を書いても文句を言わなかったので、このようなコードに何の警告も出なかった。
#include<stdio.h>
int main() {
int x = 0;
/* おそらく意図と違う。 x == 1 と書くべきであった
-------------------------------------------------------------------------------- | |
{-# LANGUAGE OverloadedStrings #-} | |
module Main | |
( main | |
) where | |
-------------------------------------------------------------------------------- | |
import Control.Concurrent (forkIO) | |
import Control.Applicative ((<$>)) |
contMap = (arr, f, g, ans) -> | |
if ans is undefined then ans = [] | |
if arr.length is 0 and typeof g is 'function' then return g ans else return | |
f.apply @, [ | |
arr.shift() | |
(item)-> contMap arr, f, g, ans.concat([item]) | |
ans | |
] | |
# Example |
module Promise where | |
import Control.Applicative (Applicative(..)) | |
import Data.Monoid (Monoid(..)) | |
newtype Error = Error { unString :: String } deriving (Eq, Ord, Read, Show) | |
data Promise a = Failed Error | Deferred | Fulfilled a | |
deriving (Eq, Ord, Read, Show) |
/* bling.js */ | |
window.$ = document.querySelector.bind(document); | |
window.$$ = document.querySelectorAll.bind(document); | |
Node.prototype.on = window.on = function(name, fn) { this.addEventListener(name, fn); }; | |
NodeList.prototype.__proto__ = Array.prototype; | |
NodeList.prototype.on = function(name, fn) { this.forEach((elem) => elem.on(name, fn)); }; |
Interpreting Free Monads of Functor Sums | |
======================================== | |
This text deals with a way to compose certain kinds of monads, thereby mixing | |
their capabilities. It is a literate Haskell file, so let's begin with a | |
bunch of noise. | |
> {-# LANGUAGE MultiParamTypeClasses #-} | |
> {-# LANGUAGE FlexibleInstances #-} | |
> {-# LANGUAGE FlexibleContexts #-} |