Skip to content

Instantly share code, notes, and snippets.

@fumieval
fumieval / chomado.hs
Last active December 16, 2015 05:38
ぶるぶるちょまど(https://twitter.com/chomado/status/323644612357001217 )をコンビネータとして解釈する純粋関数型言語。 oは3-タプル(K, S, K)をチャーチエンコードしたものにあたる。(* ~ *)はコメント。入出力はチャーチエンコードされた自然数のリスト。
import Control.Applicative
import Data.Word
import System.Environment
import Text.Trifecta
import Control.Monad
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BL
import qualified Codec.Binary.UTF8.String as UTF8
infixl 9 :$
@chomado
chomado / sort2.hs
Last active December 17, 2015 11:19
さっき書いたsortのやつ、case of使わないで書きなおしてみました。case ofとかOCamlのmatch withとか使わなくても普通にパターンマッチできるのスゴイですHaskell感動しました
mysort2 :: [Int] -> [Int]
mysort2 [] = []
mysort2 (first : rest) = insert (mysort2 rest) first
where
insert [] n = [n]
insert (first : rest) n
| first < n = first : insert rest n
| otherwise = n : first : rest
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
module Main where
----
-- Coyoneda
data CoYoneda f x = forall b. CoYoneda (b -> x) (f b)
instance Functor (CoYoneda f) where