Blogged by Ujihisa. Standard methods of programming and thoughts including Clojure, Vim, LLVM, Haskell, Ruby and Mathematics written by a Japanese programmer. github/ujihisa

Wednesday, September 16, 2009

rubyconf japanese attendee skype public chat room

http://tinyurl.com/klx3ap

Mac OS X Desktop Application Development with Ruby

takao7 published a book "Mac OS X Desktop Application Development with Ruby" (『RubyによるMac OS Xデスクトップアプリケーション開発入門』) I am interested in developing OS X local applications with Ruby very much. #RHCBK

This book is written in Japanese, but I think somebody will translate it to English.

I'm also interested the abbreviation name of this book's title RHC. The title reminds rubyists the Ruby Bible RHG: Ruby Hacking Guide by Minero Aoki.

Monday, September 14, 2009

Git Lessons Learned For Speedup

TOPIC: To know whether we can push or not without doing pull.

git status isn't reliable for this purpose. Even if the result was the following, it doesn't mean we can push without pull. The current branch may be outdated with origin's.

# On branch master
nothing to commit (working directory clean)

git ls-remote origin master is also not. Once we committed, the sha1 is already changed, therefore we cannot compare it to remote's.

So, although this has side effects, git fetch is the best solution for this problem. Doing git fetch periodically on background, and then checking git status is fast and easy way.

In short,

$ ruby -e 'loop { `git fetch` }'

In another shell.

Thursday, September 10, 2009

I Will Speak At RubyConf 2009

rubyconf2009

http://rubyconf.org/

I got an email from Ruby Central this morning.

Thank you for submitting a proposal to speak at RubyConf 2009. We're happy to let you know that your proposal, "Hacking parse.y", has been selected for inclusion in the program.

(snip)

The talks are 45 minutes long, including any Q&A you want to do.

Victoryy!

[Fri Sep 11 19:35:10 PDT 2009 Added]

Wednesday, September 9, 2009

RubyKaigi2009 Best Shots

Do you remember RubyKaigi this year in Japan? Here I'll pick some photos up. They are from Flickr CC Search. (If you don't want to show some of them, feel free to ask me).

http://www.flickr.com/photos/recompile_net/3732360065/

Jugyo the Termtter Founder

http://www.flickr.com/photos/koichiroo/3739822729/

"Java is just a shit" by kitaj (The person is not kitaj but kazuhiko.)

http://www.flickr.com/photos/koichiroo/3740461484/

Higeno Yamaotoko and Ninja of mystery

http://www.flickr.com/photos/recompile_net/3732368117/

RubyKaigi2009 great Staff

http://www.flickr.com/photos/recompile_net/3735212805/

Very young rubyist with "Enterprise Rails"

http://www.flickr.com/photos/33304338@N05/3738447946/

"Why" in Japanese

http://www.flickr.com/photos/kakutani/3745964866/

Council of War

http://www.flickr.com/photos/koichiroo/3739567849/ http://www.flickr.com/photos/koichiroo/3740339276/

TermtterKaigi2009

http://www.flickr.com/photos/darashi/3757919788/

<3

http://www.flickr.com/photos/recompile_net/3732288679/

Kakutani The Ruby Evangelist

http://www.flickr.com/photos/33304338@N05/3732661890/

Typical Programming Style

http://www.flickr.com/photos/koichiroo/3731962457/

Arton and me

http://www.flickr.com/photos/koichiroo/3732781410/

Matz (next to me!)

http://www.flickr.com/photos/iogi/3752528300/

Emobile Hacks

Wednesday, September 2, 2009

Summary: Haskell in the Real World

I read a paper.

Curt Sampson "Experience Report: Haskell in the Real World Writing a Commercial Program in Haskell", draft of submission to ICFP 2009

This paper is not for theoretical purpose but for practical one even though the title includes the purely functional language Haskell.

I have been using Haskell for 3 years, but for draft or experimental one, not for actual production. In contrast Curt Sampson, the author of the paper, used Haskell for production code int the real world.

The paper in short

  • Curt Sampson is an experienced Java programmer, who knows C and Ruby as well.

  • He got interested in functional programming languages due to Paul Graham indirectly.

  • He wrote a financial application in Haskell for his client in the spring of 2008, instead of in Java.

  • "We explained that, for us, switching languages every few years was a normal technology upgrade,"

  • He looked for a language which provides concise yet expressive code, so that his client can read and modify them.

  • It's important not to have to change his tool for new language; e.g. Smalltalk needs special environments.

  • He decided to use Haskell instead of OCaml or Scala, because:
    • Once he considered to use OCaml, but the syntax was not clear enough for him; Double semicolons and lack of overloaded functions mattered.
    • Once he considered to use Scala, but he got dissapointed to know that it couldn't run native code.
  • Haskell codes are readable even for non-programmers.

  • He wrote his own parser library, to offer stateful parsing with ByteString in contrary to the standard library Parsec.

  • Haskell needs fewer lines of test code than Ruby.

  • Haskell is more portable than C++ even when his application involved interfacing with the Microsoft products. GHC has a good FFI.

  • Lazy evaluation causes two problems, threads and space leaks. GHC's profiler helps solving the problems, but not enough.

Conclusion: Haskell is the ultimate language.

Tuesday, September 1, 2009

Installing JHC Via Cabal on Haskell Platform

Haskell Platform may make us happier. I tried to install jhc the haskell compiler via cabal of my haskell platform.

$ cabal install jhc -v
/usr/bin/ghc --numeric-version
looking for package tool: ghc-pkg near compiler in /usr/bin
found package tool in /usr/bin/ghc-pkg
/usr/bin/ghc-pkg --version
/usr/bin/ghc --supported-languages
Reading installed packages...
/usr/bin/ghc-pkg dump --global
/usr/bin/ghc-pkg dump --user
Reading available packages...
Resolving dependencies...
selecting jhc-0.5.20081118.3 (hackage) and discarding jhc-0.5.20081118,
0.5.20081118.1 and 0.5.20081118.2
selecting base-3.0.3.1 (installed) and 4.1.0.0 (installed) and discarding
syb-0.1.0.0 and 0.1.0.1
selecting ghc-prim-0.1.0.0 (installed)
selecting integer-0.1.0.1 (installed)
selecting rts-1.0 (installed)
selecting syb-0.1.0.1 (installed)
In order, the following would be installed:
jhc-0.5.20081118.3 (new package)
jhc-0.5.20081118.3 has already been downloaded.
Extracting
/Users/ujihisa/.cabal/packages/hackage.haskell.org/jhc/0.5.20081118.3/jhc-0.5.20081118.3.tar.gz
to
/var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/jhc-0.5.20081118.342599...
Configuring jhc-0.5.20081118.3...
Dependency base -any && ==3.0.3.1: using base-3.0.3.1
Using Cabal-1.6.0.3 compiled by ghc-6.10
Using compiler: ghc-6.10.3
Using install prefix: /Users/ujihisa/.cabal
Binaries installed in: /Users/ujihisa/.cabal/bin
Libraries installed in:
/Users/ujihisa/.cabal/lib/jhc-0.5.20081118.3/ghc-6.10.3
Private binaries installed in: /Users/ujihisa/.cabal/libexec
Data files installed in: /Users/ujihisa/.cabal/share/jhc-0.5.20081118.3
Documentation installed in: /Users/ujihisa/.cabal/share/doc/jhc-0.5.20081118.3
Using alex version 2.3.1 found on system at: /opt/local/bin/alex
Using ar found on system at: /usr/bin/ar
No c2hs found
No cpphs found
No ffihugs found
Using gcc version 4.0.1 found on system at: /usr/bin/gcc
Using ghc version 6.10.3 found on system at: /usr/bin/ghc
Using ghc-pkg version 6.10.3 found on system at: /usr/bin/ghc-pkg
No greencard found
Using haddock version 2.4.2 found on system at: /usr/bin/haddock
Using happy version 1.18.2 found on system at: /usr/local/bin/happy
No hmake found
Using hsc2hs version 0.67 found on system at: /usr/bin/hsc2hs
No hscolour found
No hugs found
No jhc found
Using ld found on system at: /usr/bin/ld
No nhc98 found
Using pkg-config version 0.23 found on system at: /opt/local/bin/pkg-config
Using ranlib found on system at: /usr/bin/ranlib
Using strip found on system at: /usr/bin/strip
Using tar found on system at: /usr/bin/tar
/usr/bin/gcc /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/42599.c -o /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/42599 -D__GLASGOW_HASKELL__=610 -I. -I/Library/Frameworks/GHC.framework/Versions/610/usr/lib/ghc-6.10.3/base-4.1.0.0/include -I/Library/Frameworks/GHC.framework/Versions/610/usr/lib/ghc-6.10.3/include -IPAPI_INCLUDE_DIR
cabal: Package jhc-0.5.20081118.3 can't be built on this system.
cabal: Error: some packages failed to install:
jhc-0.5.20081118.3 failed during the building phase. The exception was:
exit: ExitFailure 1

;-(

So, as blackdog suggested, I decided to build jhc by the source code.

jhc official site explains first I have to get source by darcs, but at the time I didn't have it. Let's install darcs.

$ cabal install darcs
Resolving dependencies...
[1 of 2] Compiling Distribution.ShellHarness ( /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/darcs-2.3.099527/darcs-2.3.0/Distribution/ShellHarness.hs, /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/darcs-2.3.099527/darcs-2.3.0/dist/setup/Distribution/ShellHarness.o )
[2 of 2] Compiling Main             ( /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/darcs-2.3.099527/darcs-2.3.0/Setup.lhs, /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/darcs-2.3.099527/darcs-2.3.0/dist/setup/Main.o )
Linking /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/darcs-2.3.099527/darcs-2.3.0/dist/setup/setup ...
Configuring darcs-2.3.0...
Preprocessing library darcs-2.3.0...
Preprocessing executables for darcs-2.3.0...
Building darcs-2.3.0...

src/Darcs/Commands/Optimize.lhs:26:7:
    Could not find module `Text.Regex':
      There are files missing in the `regex-compat-0.92' package,
      try running 'ghc-pkg check'.
      Use -v to see a list of the files searched for.
cabal: Error: some packages failed to install:
darcs-2.3.0 failed during the building phase. The exception was:
exit: ExitFailure 1

What. OK. I have to do ghc-pkg check. I see.

$ ghc-pkg check
There are problems in package network-2.2.1.4:
  import-dirs: /Users/ujihisa/.cabal/lib/network-2.2.1.4/ghc-6.10.3 doesn't exist or isn't a directory
  library-dirs: /Users/ujihisa/.cabal/lib/network-2.2.1.4/ghc-6.10.3 doesn't exist or isn't a directory
  include-dirs: /Users/ujihisa/.cabal/lib/network-2.2.1.4/ghc-6.10.3/include doesn't exist or isn't a directory
  file Network.hi is missing
  file Network/BSD.hi is missing
  file Network/Socket/Internal.hi is missing
  file Network/Socket.hi is missing
  file Network/URI.hi is missing
  cannot find libHSnetwork-2.2.1.4.a on library path
There are problems in package HTTP-4000.0.7:
  import-dirs: /Users/ujihisa/.cabal/lib/HTTP-4000.0.7/ghc-6.10.3 doesn't exist or isn't a directory
  library-dirs: /Users/ujihisa/.cabal/lib/HTTP-4000.0.7/ghc-6.10.3 doesn't exist or isn't a directory
  file Network/BufferType.hi is missing
  file Network/Stream.hi is missing
  file Network/StreamDebugger.hi is missing
  file Network/StreamSocket.hi is missing
  file Network/TCP.hi is missing
  file Network/HTTP.hi is missing
  file Network/HTTP/Headers.hi is missing
  file Network/HTTP/Base.hi is missing
  file Network/HTTP/Stream.hi is missing
  file Network/HTTP/HandleStream.hi is missing
  file Network/Browser.hi is missing
  file Network/HTTP/Base64.hi is missing
  file Network/HTTP/MD5.hi is missing
  file Network/HTTP/MD5Aux.hi is missing
  file Network/HTTP/Utils.hi is missing
  cannot find libHSHTTP-4000.0.7.a on library path
There are problems in package regex-base-0.93.1:
  import-dirs: /Users/ujihisa/.cabal/lib/regex-base-0.93.1/ghc-6.10.3 doesn't exist or isn't a directory
  library-dirs: /Users/ujihisa/.cabal/lib/regex-base-0.93.1/ghc-6.10.3 doesn't exist or isn't a directory
  file Text/Regex/Base.hi is missing
  file Text/Regex/Base/RegexLike.hi is missing
  file Text/Regex/Base/Context.hi is missing
  file Text/Regex/Base/Impl.hi is missing
  cannot find libHSregex-base-0.93.1.a on library path
There are problems in package regex-posix-0.94.1:
  import-dirs: /Users/ujihisa/.cabal/lib/regex-posix-0.94.1/ghc-6.10.3 doesn't exist or isn't a directory
  library-dirs: /Users/ujihisa/.cabal/lib/regex-posix-0.94.1/ghc-6.10.3 doesn't exist or isn't a directory
  file Text/Regex/Posix.hi is missing
  file Text/Regex/Posix/Wrap.hi is missing
  file Text/Regex/Posix/String.hi is missing
  file Text/Regex/Posix/Sequence.hi is missing
  file Text/Regex/Posix/ByteString.hi is missing
  file Text/Regex/Posix/ByteString/Lazy.hi is missing
  cannot find libHSregex-posix-0.94.1.a on library path
There are problems in package regex-compat-0.92:
  import-dirs: /Users/ujihisa/.cabal/lib/regex-compat-0.92/ghc-6.10.3 doesn't exist or isn't a directory
  library-dirs: /Users/ujihisa/.cabal/lib/regex-compat-0.92/ghc-6.10.3 doesn't exist or isn't a directory
  file Text/Regex.hi is missing
  cannot find libHSregex-compat-0.92.a on library path
There are problems in package time-1.1.4:
  import-dirs: /Users/ujihisa/.cabal/lib/time-1.1.4/ghc-6.10.3 doesn't exist or isn't a directory
  library-dirs: /Users/ujihisa/.cabal/lib/time-1.1.4/ghc-6.10.3 doesn't exist or isn't a directory
  include-dirs: /Users/ujihisa/.cabal/lib/time-1.1.4/ghc-6.10.3/include doesn't exist or isn't a directory
  file Data/Time/Calendar.hi is missing
  file Data/Time/Calendar/MonthDay.hi is missing
  file Data/Time/Calendar/OrdinalDate.hi is missing
  file Data/Time/Calendar/WeekDate.hi is missing
  file Data/Time/Calendar/Julian.hi is missing
  file Data/Time/Calendar/Easter.hi is missing
  file Data/Time/Clock.hi is missing
  file Data/Time/Clock/POSIX.hi is missing
  file Data/Time/Clock/TAI.hi is missing
  file Data/Time/LocalTime.hi is missing
  file Data/Time/Format.hi is missing
  file Data/Time.hi is missing
  file Data/Time/Calendar/Private.hi is missing
  file Data/Time/Calendar/Days.hi is missing
  file Data/Time/Calendar/Gregorian.hi is missing
  file Data/Time/Calendar/JulianYearDay.hi is missing
  file Data/Time/Clock/Scale.hi is missing
  file Data/Time/Clock/UTC.hi is missing
  file Data/Time/Clock/CTimeval.hi is missing
  file Data/Time/Clock/UTCDiff.hi is missing
  file Data/Time/LocalTime/TimeZone.hi is missing
  file Data/Time/LocalTime/TimeOfDay.hi is missing
  file Data/Time/LocalTime/LocalTime.hi is missing
  file Data/Time/Format/Parse.hi is missing
  cannot find libHStime-1.1.4.a on library path
There are problems in package rts-1.0:
  include-dirs: PAPI_INCLUDE_DIR doesn't exist or isn't a directory

The following packages are broken, either because they have a problem
listed above, or because they depend on a broken package.
network-2.2.1.4
HTTP-4000.0.7
regex-base-0.93.1
regex-posix-0.94.1
regex-compat-0.92
time-1.1.4
rts-1.0
binary-0.5.0.1
digest-0.0.0.6
utf8-string-0.3.5
zip-archive-0.1.1.3
Diff-0.1.2
QuickCheck-2.1.0.1
binary-0.5
derive-0.1.4
dlist-0.5
fingertree-0.0.1.0
ghc-paths-0.1.0.5
pureMD5-1.0.0.0
rosezipper-0.1
split-0.1.1
terminfo-0.3.0.2
transformers-0.1.4.0
data-accessor-0.2.0.2
monads-fd-0.0.0.1
data-accessor-monads-fd-0.2
pointedlist-0.3.5
uniplate-1.2.0.3
unix-compat-0.1.2.1
utility-ht-0.0.5.1
data-accessor-template-0.2.1.1
vty-3.1.8.4
language-c-0.3.1.1
haskeline-0.6.1.6
mmap-0.4.1
zlib-0.5.2.0
hashed-storage-0.3.7
haddock-2.4.2
ghc-6.10.3
ghc-prim-0.1.0.0
integer-0.1.0.1
base-4.1.0.0
syb-0.1.0.1
base-3.0.3.1
array-0.2.0.0
packedstring-0.1.0.1
containers-0.2.0.1
bytestring-0.9.1.4
old-locale-1.0.0.1
old-time-1.0.0.2
filepath-1.1.0.2
unix-2.3.2.0
directory-1.0.0.3
process-1.0.1.1
pretty-1.0.1.0
hpc-0.5.0.3
template-haskell-2.3.0.1
Cabal-1.6.0.3
random-1.0.0.1
haskell98-1.0.1.0
extensible-exceptions-0.1.1.0
network-2.2.1
time-1.1.3
dph-base-0.3
dph-prim-interface-0.3
dph-prim-seq-0.3
dph-prim-par-0.3
dph-seq-0.3
dph-par-0.3
OpenGL-2.2.1.1
network-2.2.1.1
haskell-src-1.0.1.3
GLUT-2.1.1.2
regex-base-0.72.0.2
QuickCheck-1.2.0.0
mtl-1.1.0.2
HUnit-1.2.0.3
cgi-3001.1.7.1
html-1.0.1.2
editline-0.2.1.0
stm-2.1.1.2
regex-posix-0.72.0.3
regex-compat-0.71.0.1
parsec-2.1.0.1
parallel-1.1.0.1
HTTP-4000.0.6
fgl-5.4.2.2
zlib-0.5.0.0
xhtml-3000.2.0.1
time-1.1.2.4

?

$ cabal reinstall regex-compat
unrecognised command: reinstall (try --help)
$ cabal install regex-compat --reinstall
Resolving dependencies...
Downloading regex-compat-0.92...
Configuring regex-compat-0.92...
Preprocessing library regex-compat-0.92...
Building regex-compat-0.92...

Text/Regex.hs:35:7:
    Could not find module `Text.Regex.Posix':
      There are files missing in the `regex-posix-0.94.1' package,
      try running 'ghc-pkg check'.
      Use -v to see a list of the files searched for.
cabal: Error: some packages failed to install:
regex-compat-0.92 failed during the building phase. The exception was:
exit: ExitFailure 1

???

OK. I forget them. Let's install by stable tar ball. http://repetae.net/dist/jhc-0.7.2.tar.gz this one.

$ cd src
$ wget http://repetae.net/dist/jhc-0.7.2.tar.gz                                                          [20:35:46]
$ cd jhc-0.7.2
$ ./configure --prefix=`pwd`/jhc
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ac-macros/install-sh -c -d
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking build system type... i386-apple-darwin9.8.0
checking host system type... i386-apple-darwin9.8.0
checking whether ln -s works... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... no
checking for ghc... /usr/bin/ghc
checking for DrIFT... no
DrIFT not found: using preprocessed files
checking for module Data.Generics.Instances... in package syb
checking for hsc2hs... /usr/bin/hsc2hs
configure: creating ./config.status
config.status: creating Makefile
config.status: creating jhc.spec
config.status: creating src/Version/Config.hs
config.status: creating docs/building.mkd
config.status: creating src/cbits/config.h
$ make && make install
make  all-am
/usr/bin/ghc  -fbang-patterns -O -hide-all-packages -package base -package syb  -W -fno-warn-unused-matches  -fwarn-type-defaults -i -i./drift_processed -i./src  -i./src -odir ./src -hidir ./src -package fgl -package regex-compat -package random -package array -package readline -package directory -package bytestring -package binary -package pretty -package mtl -package containers -package unix  -package haskell98 -package utf8-string  -package zlib -fallow-undecidable-instances  -fglasgow-exts -fallow-overlapping-instances --make src/Main.hs src/StringTable/StringTable_cbits.o  src/cbits/md5sum.o -o jhc

on the commandline:
    Warning: -fbang-patterns is deprecated: use -XBangPatterns or pragma {-# LANGUAGE BangPatterns#-} instead

on the commandline:
    Warning: -fallow-undecidable-instances is deprecated: use -XUndecidableInstances or pragma {-# LANGUAGE UndecidableInstances#-} instead

on the commandline:
    Warning: -fallow-overlapping-instances is deprecated: use -XOverlappingInstances or pragma {-# LANGUAGE OverlappingInstances#-} instead
<command line>: unknown package: readline
make[1]: *** [jhc] Error 1
make: *** [all] Error 2

I gave up.

Followers