Skip to content

Instantly share code, notes, and snippets.

@tokiwoousaka
tokiwoousaka / gist:4696909
Created February 2, 2013 11:11
困った
module Main where
class C c where
class A a where
cFrom :: C b => a -> b
instance C c => A ((,) c a) where
cFrom x = fst x --ghc cant deduce c 2 b
@tokiwoousaka
tokiwoousaka / gist:5213644
Created March 21, 2013 14:51
Control.Lensの再発明
module Main where
import Data.Functor.Identity
infixr 4 .~
infixl 1 &
instance Show a => Show (Identity a) where
show x = "Identity " ++ (show $ runIdentity x)
type Setter s t a b = (a -> Identity b) -> s -> Identity t
@tokiwoousaka
tokiwoousaka / gist:5230486
Created March 24, 2013 04:11
Control.Lensの再発明(2) Getterのほう
{-# LANGUAGE RankNTypes #-}
module Main where
import Data.Functor.Constant
import Data.Foldable
import Data.Traversable
import Data.Monoid
import Control.Applicative
infixl 8 ^.
@tokiwoousaka
tokiwoousaka / gist:5230679
Last active December 15, 2015 08:28
Control.Lensの再発明(3) でけたー!!!
{-# LANGUAGE RankNTypes #-}
module Main where
import Data.Functor.Identity
import Data.Functor.Constant
infixl 8 ^.
infixr 4 .~
infixl 1 &
@tokiwoousaka
tokiwoousaka / gist:5473224
Last active December 16, 2015 17:49
Rubyのクラス何でも出来すぎだろコレ
class Foo
def hoge
print "HogeHoge\n"
end
end
F = Foo.new
F.hoge
class Foo
@tokiwoousaka
tokiwoousaka / gist:5480615
Last active December 16, 2015 18:49
egisonのmatcherの定義。 見様見真似で書いてみたけどどうしてこーなるのか解らんw
(define $hoge
(matcher {
;; <primitive-pp>
[,$val [] {[$tgt
(match [val tgt] [hoge hoge] {
[[<aaa> <aaa>] {[]}]
[[<bbb> <bbb>] {[]}]
[[<ccc> <ccc>] {[]}]
[_ {}]})]}]
;; <primitive-dp>
@tokiwoousaka
tokiwoousaka / gist:5481512
Last active December 16, 2015 18:59
egisonを使ったMaybeのmatcher定義
(define $maybe
(lambda [$a]
(matcher {
;; <primitive-pp>
[,$val [a] {[$tgt
(match [val tgt] [(maybe a) (maybe a)] {
[[<just $x> <just ,x>] {[x]}]
[[<nothing> <nothing>] {[]}]
[_ {}]})]}]
;; <primitive-dp>
@tokiwoousaka
tokiwoousaka / gist:5495959
Last active December 16, 2015 20:58
たけとんさんの書いたeitherで遊んでみた
(define $maybe
(lambda [$a]
(matcher {
;; <primitive-pp>
[,$val [a] {[$tgt
(match [val tgt] [(maybe a) (maybe a)] {
[[<just $x> <just ,x>] {[x]}]
[[<nothing> <nothing>] {[]}]
[_ {}]})]}]
;; <primitive-dp>
@tokiwoousaka
tokiwoousaka / gist:5507329
Last active December 16, 2015 22:29
egisonではリストもmaybeも、matcherを適切に実装する事で、同じマッチ式でパターンマッチする事ができる。
(define $maybe
(lambda [$a]
(matcher {
;; <primitive-pp>
[,$val [a] {[$tgt
(match [val tgt] [(maybe a) (maybe a)] {
[[<just $x> <just ,x>] {[x]}]
[[<nothing> <nothing>] {[]}]
[_ {}]})]}]
;; <primitive-dp>
@tokiwoousaka
tokiwoousaka / .vimrc
Created June 12, 2013 15:56
仕事先で使えるよう公開
" 検索文字列ハイライト
set hlsearch
"""""""""""""""""""""""""""""""""""""""""""""""""
" 実行
:function ExecFile()
:w
:if &filetype == "haskell"