Skip to content

Instantly share code, notes, and snippets.

@kagamilove0707
kagamilove0707 / fizzbuzz_for_thread.rb
Last active January 1, 2016 07:09
並列化時代のためのFizzBuzzですー>ω<
#################################################################
#並列化時代のためのFizzBuzzです~>ω<
#Author : 月影
#Date : 2013/12/24
#License : お好きにどうぞ(Public Domainというやつですー>ω<)
#Comment : 聖なる夜に何をやっているんでしょう……( ̄▽ ̄ll)
#################################################################
#プログラムを止める際に実行されますです~>ω<
#下の方で無限ループしているので、Ctrl-Cで止めてくださいです(≧∇≦)b
@kagamilove0707
kagamilove0707 / lens.hs
Created September 28, 2013 16:28
Storeを眺めていたらLensが出てきそうな気がしたのですけれど、なにか違う気がしますです><
import Prelude hiding ((.))
import Control.Category
data Store s a = Store {
set' :: s -> a, view' :: s}
newtype Lens' b a = Lens {
runLens :: a -> Store b a}
type Lens a b = Lens' b a
@kagamilove0707
kagamilove0707 / Scott.hs
Created September 15, 2013 05:38
Freeモナドのスコット・エンコーディングによる実装ですー>ω< kazu-yamamoto氏のhttps://gist.github.com/kazu-yamamoto/4064634#file-gistfile1-hs-L76を参考にさせていただきましたのです(`・ω・´)
{-# LANGUAGE Rank2Types, DeriveFunctor, LambdaCase #-}
module Control.Monad.Free.Scott (($|), Free(..), free', pure', liftF) where
infixl 1 $|
($|) :: (a -> b) -> a -> b
f $| x = f x
-- Type
newtype Free f a = Free {
@kagamilove0707
kagamilove0707 / tinf2.hs
Created July 16, 2013 07:22
型推論機にlet式とパーサーを追加してみましたですー>ω< 適当遊んでみてくださいですー>ω<
{-# Language TemplateHaskell, QuasiQuotes, FlexibleContexts #-}
import Text.Peggy hiding (Expr, space)
import Control.Monad.State
type Name = String
data Type =
TInt|
TBool|
TVar Name|
TFun Type Type deriving (Show, Eq)
import Control.Monad.State
type Name = String
data Type =
TInt|
TBool|
TVar Name|
TFun Type Type deriving (Show, Eq)
data Expr =
EInt Int|
@kagamilove0707
kagamilove0707 / SafeList_by_GADTs.hs
Created June 23, 2013 07:04
tailが動くものが作れたので公開しておきますです>ω< 型安全なリストですー>ω<
-- Generalized Algebraic Data Types(一般的代数データ型)が使えるようになるみたいです>ω<
{-# LANGUAGE GADTs #-}
module Main where
import Prelude hiding (head, tail, map)
-- EmptyとNonEmptyもリストのような構造にすることで、
-- あと何回tailすることが出来るのか、という情報を保持しますです>ω<
data Empty
data NonEmpty x
@kagamilove0707
kagamilove0707 / entry-parsec.hs
Last active December 18, 2015 13:19
Parsec入門したかったので書いてみましたですー>ω< 数値リテラルのパーサーです(`・ω・´)
import Control.Applicative ((<$>),(<*>),(*>),(<*))
import Data.Char (ord)
import Text.Parsec (try, char, eof, oneOf, many, many1, parse, (<|>))
import Text.Parsec.String (Parser)
{-
number ::= binary | octal | decimal | hexadecimal | zero
binary ::= '0' ('b'|'B') ('0'|'1')+
octal ::= '0' ('o'|'O') ('0'..'7')+
decimal ::= ('1'..'9') ('0'..'9')*
@kagamilove0707
kagamilove0707 / janken.hs
Last active December 18, 2015 13:09
OrderingのMonoid実装を使って書いたじゃんけんです>ω< unsafeInterleaveIOを使ってどうにか動くようにしてみました>< もっとうまい方法を知っていたら教えていただけると幸いですm(_ _)m
import Control.Monad
import Data.Monoid
import System.IO
import System.Random
data Janken = Guu|Choki|Paa deriving (Show, Read, Eq, Enum)
instance Ord Janken where
Guu `compare` Choki = LT
Choki `compare` Paa = LT
@kagamilove0707
kagamilove0707 / control-arrow.js
Created June 15, 2013 04:37
HaskellのArrowをJavaScriptで再現してみました>ω<
(function() {
'use strict';
function toArray(n, args) {
return Array.prototype.slice.call(args, n);
}
function extend(obj, it) {
return Object.keys(obj).reduce(function(it, name) {
it[name] = obj[name];
@kagamilove0707
kagamilove0707 / Pair.hs
Created June 9, 2013 05:44
Pairモナドですー>ω< どう役立てるかはあなた次第(`・ω・´)
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Data.Pair (Pair, pair, (<:>)) where
import Data.Monoid
import Control.Applicative
newtype Pair a = Pair (a, a) deriving (Show, Eq, Monoid)
infixl 5 <:>
pair, (<:>) :: a -> a -> Pair a