Haskell で .NET(Shift_JIS)

hs-dotnet-0.4.0 を入れてみました。

$ runghc Setup.hs configure
Configuring hs-dotnet-0.4.0...

$ runghc Setup.hs build
Preprocessing library hs-dotnet-0.4.0...
Building hs-dotnet-0.4.0...
[  1 of 167] Compiling NET.System.TypeCodeTy ( NET\System\TypeCodeTy.hs, dist\build\NET\System\TypeCodeTy.o )
[  2 of 167] Compiling NET.Base         ( NET\Base.hs, dist\build\NET\Base.o )
  (snip)
[167 of 167] Compiling NET.System.Char  ( NET\System\Char.hs, dist\build\NET\System\Char.o )
Registering hs-dotnet-0.4.0...

$ runghc Setup.hs install
Installing library in C:\Program Files\Haskell\hs-dotnet-0.4.0\ghc-6.12.3
Registering hs-dotnet-0.4.0...
Registering hs-dotnet Assembly..
OK!
Registering Assembly COM Interop classes..
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.3053
Copyright (C) Microsoft Corporation 1998-2004.  All rights reserved.

Types registered successfully
OK!

examples の Forms.hs を動かしてみます。

$ ghc --make Forms.hs -o form.exe
[1 of 1] Compiling Main             ( Forms.hs, Forms.o )
Linking form.exe ...
$ ./form.exe


表示する文字列はCinnamonを使って ucs4 から Sjis へ変換しています。
ソースは utf-8 でないとコンパイル時にエラーになりますので utf-8 で記述します。ソースは utf-8 ですが、コンパイルすると文字列は ucs4 になりますので、Windows で表示させようとするときは ucs4 から Sjis へ変換する必要があります。

import NET
import Control.Concurrent
import Cinnamon.Ucs (ucs4ToSjis)

type Control a = Object a
type Config a  = Control a -> IO ()
type Setter a b = b -> Config a

build :: IO ()
build = do
  frm <- (mkCtrl "System.Windows.Forms.Form" [option setSize (200, 200)] :: IO (Object ()))
  btn <- frm # addCtrl "System.Windows.Forms.Button" 
                       [ option setText (ucs4ToSjis "押して!")
   		       , option setSize     (50,50)
		       , option setLocation (75,75)
		       ]
  lab <- frm # addCtrl "System.Windows.Forms.Label" 
                       [ option setText (ucs4ToSjis "クリック: 0")
		       , option setSize     (50,50)
		       , option setLocation (0,0)
		       ]
   -- start up an counting, updating thread.
  ch <- newChan
  forkIO (updateLabel lab 0 ch)
  event btn "Click" (\_ _ -> do
                        msgBox (ucs4ToSjis "こんにちは!") (ucs4ToSjis "おめでとう")
			writeChan ch True)
(略)

立ち上がりが死ぬほど遅いです。
cinnamon-0.2 のインストールメモ。