Cayenneのモジュールシステム

とかがどうなってるのか分からない。確かちらっと見た時は、"そんなもんは冗長に入れなくても素直に書けるお"とかどっかに書いてた気がするんだけど晩ご飯とか食べながらそれをpaperから調べる事にして、取りあえずprintfが書けたので張ってみる

-- このファイルはprint.cyとする
module sample$print =
#include Prelude
struct
concrete
PrintfType :: String -> #
PrintfType (Nil)        = String
PrintfType ('%':'d':cs) = Integer-> PrintfType cs
PrintfType ('%':'s':cs) = String -> PrintfType cs
PrintfType (c:cs)       =           PrintfType cs

my_printf :: (fmt :: String) -> PrintfType fmt
my_printf fmt = pr fmt ""

private
pr :: (fmt :: String) -> String -> PrintfType fmt
pr (Nil)      	res = res
pr ('%':'d':cs) res = \ i -> pr cs (res ++ show i)
pr ('%':'s':cs) res = \ s -> pr cs (res ++ s)
pr (c:cs)       res = pr cs (res ++ c:Nil)
-- このファイルはuse.cyとする
module sample$use = 
#include Prelude
open sample$print use * in

do Monad_IO
  putStrLn (my_printf "Hello,World!!")
  putStrLn (my_printf "%d %d %s Hoge" 1 2 "Foo")

コンパイルと実行方法

cayenne print.cy
cayenne use.cy

ここまでで、sampleというディレクトリが出来ている筈。
実行ファイルを作るには

cayenee 'sample$use'

とする。
a.outが出来るはずなので、./a.out

/Users/ranha/Cayenne/misc% cayenne print.cy 
/Users/ranha/Cayenne/misc% cayenne use.cy 
/Users/ranha/Cayenne/misc% cayenne 'sample$use' 
/Users/ranha/Cayenne/misc% ./a.out 
Hello,World!!
1 2 Foo Hoge

でけた!!


do Monad_IOとか可愛いね。