It seems I had an 'aha!' time with monad today, finally. It seems monad is everywhere.
In a functional world with currying, we can think all functions are in the type x -> y. We can divide those functions into two category:
1. a -> a, these are functions who have same input and output type
2. a -> b, there are the functions who have different input and output type
Functions in category one can work with functions have the same type as them easily, suppose you have f::Int->Int and g::Int->Int, you can combine them as you wish, like f.f.f.g.g.g.f.g.g.f. This is why people like functional programming.
But this is not true for functions in 2rd category. Suppose you have f::Int->Float and g::Int->Float, how would you combine them? You can do neither f.g nor g.f, the types just don't match. As you can feel, there's much more functions in 2rd category than those in 1st category in real world. So monad comes to rescue.
Monad helps functions in 2rd category behave like those ones in 1st category - it can 'lift' a 2rd category function to 1st category, with one of its core functions named bind:
bind :: (a -> b) -> (b -> b)
In haskell b is a Monad. If you have read a tutorial take Maybe monad as example, you may have an intuition that monad is a 'wrapper' which wrap something. That's not exactly. The key here is to define a way to convert a value of type a to a value to type b, and vice vesa. Wrap a value is an easy and intuitive way to do the conversion, but not the only way (e.g. List Monad is a good example). So you can think everything as Monad, because type a -> b function is everywhere. Yes Float is monad, because there is a function in type Int -> Float and you can define a bind in type (Int -> Float) -> (Float -> Float).
Jul 27, 2009
Jun 15, 2009
[ANN] Rubytest.vim 0.9.6 Released
Rubytest.vim 0.9.6 is just released. This version contains some small fix:
* support rspec examples looks like
example "this is an example" do
* correctly handle single/double quote escape for rspec examples and vanilla testcases
Check it out here: http://www.vim.org/scripts/script.php?script_id=2612
* Rubytest.vim is a vim plugin which helps you run ruby tests (including vanilla testcases, rspec examples, shoulda examples ..) quickly.
* support rspec examples looks like
example "this is an example" do
* correctly handle single/double quote escape for rspec examples and vanilla testcases
Check it out here: http://www.vim.org/scripts/script.php?script_id=2612
* Rubytest.vim is a vim plugin which helps you run ruby tests (including vanilla testcases, rspec examples, shoulda examples ..) quickly.
Jun 2, 2009
Infinity in Ruby
I learned this from a post today:
But ruby is not like haskell, which eval lazily - so don't try everything.to_a[0..100] :)
irb(main):001:0> Infinity = 1/0.0
=> Infinity
irb(main):002:0> (0..Infinity).include?(100000000000000)
=> true
irb(main):003:0> (0..Infinity).include?(-1)
=> false
irb(main):004:0> (-Infinity..0).include?(-1)
=> true
irb(main):005:0> (-Infinity..0).include?(-100000000000000000000)
=> true
irb(main):006:0> (-Infinity..0).include?(1)
=> false
irb(main):007:0> everything = -Infinity..Infinity
=> -Infinity..Infinity
irb(main):008:0> everything.include? 0
=> true
But ruby is not like haskell, which eval lazily - so don't try everything.to_a[0..100] :)
May 12, 2009
[ANN] Rubytest.vim 0.9.5 Released
Rubytest.vim is a vim (http://www.vim.org) plugin, which helps you to run ruby test (including vanilla test, rspec, shoulda etc.) in vim.
Changelog
---------
* Support quickfix: you can view test errors in quickfix window now
* Small fixes.
Get it here: http://www.vim.org/scripts/script.php?script_id=2612
Changelog
---------
* Support quickfix: you can view test errors in quickfix window now
* Small fixes.
Get it here: http://www.vim.org/scripts/script.php?script_id=2612
May 4, 2009
The problem with young entrepreneurs
"Most of the time, this leads to the well-known case of “solutions looking for problems” - beautiful technology that can’t become a profitable business.
Best ideas are a side-effect from solving significant problems that the entrepreneurs themselves experience, observe and intimately understand. As young Web entrepreneurs, we aren’t sufficiently aware of important real-world problems, since our life mostly consists of hacking, coffee and occasional entertainment."
via
Best ideas are a side-effect from solving significant problems that the entrepreneurs themselves experience, observe and intimately understand. As young Web entrepreneurs, we aren’t sufficiently aware of important real-world problems, since our life mostly consists of hacking, coffee and occasional entertainment."
via
Apr 30, 2009
Something about latest vimperator
Latest vimperator release doesn't work well with Firefox 3.0.x and TabMixPlus: slow autocompletion, broken tab functions.
M.Terada provides two patch to make tabs work decently again, I don't know whehter it's included in vimperator's repository now, but you can download them here and here
For faster auto completion, set complete and preload options like this in your .vimperatorrc may help:
Some guys suggest setting wildmode to empty, but I don't like that idea.
Below is mine full .vimperatorrc:
M.Terada provides two patch to make tabs work decently again, I don't know whehter it's included in vimperator's repository now, but you can download them here and here
For faster auto completion, set complete and preload options like this in your .vimperatorrc may help:
set complete=sbh
set nopreload
Some guys suggest setting wildmode to empty, but I don't like that idea.
Below is mine full .vimperatorrc:
set pageinfo=gfm
set showtabline=2
set defsearch=google
set complete=sbh
set nopreload
set showstatuslinks=2
set smartcase
set newtab=all
"set wildmode=
map l gt
map h gT
map b :bmarks!<Space>
map ;; d
map s :js open("mailto:?SUBJECT='" + escape(document.title) + "'" + "&BODY=" + escape(document.getElementById("urlbar").value))<CR>
map <C-p> :pa<CR>
map <C-k> tg<Space>
map <C-u> <C-v><C-u>
map <C-y> <C-v><C-y>
map <C-R> a<Space>-tags=toread<CR>
map <C-r> :bmarks -tags=toread<CR>
map <C-d> :delbm<CR>
"map <C-l> :sidebar LiveHTTPHeaders<CR>
map <silent> <F9> :js inspectDOMDocument(document)<CR>
map <silent> <F1> :js toggle_element('toolbar-menubar');toggle_element('nav-bar')<CR>
map <silent> <F2> :emenu Edit.Preferences<CR>
map <silent> <F3> :emenu Tools.Live HTTP headers<CR>
map <silent> <F10> :exe ":o dict2 "+content.getSelection()<CR>
autocmd PageLoad .* :js modes.passAllKeys = /(mail\.google\.com)|(google\.com\/reader)/.test(buffer.URL)
set nextpattern+=^\s*下一页\s*$
set previouspattern+=^\s*上一页\s*$
javascript <<EOF
(function(){
var feedPanel = document.createElement("statusbarpanel");
feedPanel.setAttribute("id", "feed-panel-clone");
feedPanel.appendChild(document.getElementById("feed-button"));
feedPanel.firstChild.setAttribute("style", "padding: 0; max-height: 16px;");
document.getElementById("status-bar")
.insertBefore(feedPanel, document.getElementById("security-button"));
})();
EOF
javascript << EOF
toggle_element = function (name) {
document.getElementById(name).collapsed ^= 1;
}
EOF
echo ".vimperatorrc sourced"
" vim: ft=vimperator sw=2 sts=2
Apr 19, 2009
Announcement of rubytest.vim: a vim plugin aims to help you run ruby test conveniently
Rubytest.vim is a vim (http://www.vim.org) plugin, which helps you to run ruby test (including vanilla test, rspec, shoulda etc.) in vim.
http://www.vim.org/scripts/script.php?script_id=2612
Installation
------------
Copy all files to your ~/.vim directory.
Usage
-----
After installation, presst will run the test under your cursor if you are editing a ruby test file.
example:
$ cd
$ vim test/unit/user_test.rb
(move cursor into a test case, presst)
( is mapping to '\' by default in vim)
You can customize the command which will be used to run the test case by settting these options in your vimrc file:
let g:rubytest_cmd_test = "ruby %p"
let g:rubytest_cmd_testcase = "ruby %p -n '/%c/'"
let g:rubytest_cmd_spec = "spec -f specdoc %p"
let g:rubytest_cmd_example = "spec -f specdoc %p -e '%c'"
(%p will be replaced by the path of test file, %c will be replaced by the name of test case under cursor)
Default Key Bindings
--------------------
t: run test case under cursor
T: run all tests in file
You can change default key bindings:
map\ RubyTestRun " change from t to \
map] RubyFileRun " change from T to ]
http://www.vim.org/scripts/script.php?script_id=2612
http://www.vim.org/scripts/script.php?script_id=2612
Installation
------------
Copy all files to your ~/.vim directory.
Usage
-----
After installation, press
example:
$ cd
$ vim test/unit/user_test.rb
(move cursor into a test case, press
(
You can customize the command which will be used to run the test case by settting these options in your vimrc file:
let g:rubytest_cmd_test = "ruby %p"
let g:rubytest_cmd_testcase = "ruby %p -n '/%c/'"
let g:rubytest_cmd_spec = "spec -f specdoc %p"
let g:rubytest_cmd_example = "spec -f specdoc %p -e '%c'"
(%p will be replaced by the path of test file, %c will be replaced by the name of test case under cursor)
Default Key Bindings
--------------------
You can change default key bindings:
map
map
http://www.vim.org/scripts/script.php?script_id=2612
Subscribe to:
Posts (Atom)