■
さらに隙をついて
http://d.hatena.ne.jp/komamitsu/20091212/1260634388
で失敗していたSexplibのwith sexpに再挑戦
TYPE_CONV_PATH "Rule" open Sexplib open Sexplib.Sexp type price = Open of float | Top of float | Bottom of float | Close of float with sexp type price_sig = Ge of price | Gt of price | Le of price | Lt of price with sexp type cond = TimeOpen | TimeClose | Price of price_sig with sexp type action = Buy of price | Sell of price with sexp type t = (cond list * action) list with sexp let sample = " (((TimeOpen) (Buy (Open 0))) (((Price (Ge (Open +1.2))) (Price (Le (Top -0.5)))) (Sell (Open +1.2))) (((Price (Lt (Open -1.5)))) (Sell (Open -1.5))) ((TimeClose) (Sell (Close 0)))) " let parsed = t_of_sexp (scan_sexp (Lexing.from_string sample))
トップレベルでみると
# #use "topfind";; : # #camlp4o;; : # #require "sexplib.syntax";; : # #use "rule.ml";; : val parsed : (cond list * action) list = [([TimeOpen], Buy (Open 0.)); ([Price (Ge (Open 1.2)); Price (Le (Top (-0.5)))], Sell (Open 1.2)); ([Price (Lt (Open (-1.5)))], Sell (Open (-1.5))); ([TimeClose], Sell (Close 0.))]
こ、これは気分爽快だなぁ…