レコードでもliftしたい
こんないくつかの値をまとめて扱うためにレコードを定義した。
type some_record = {x:int list;y:float list}
そして、これを操作する関数をいくつか書いた。
let append {x=x1;y=y1} {x=x2;y=y2}= {x=x1@x1; y=y1@y1}
こういった関数がいくつかできてくると面倒なので、次のような高階関数を定義したくなった。
let lift f {x=x1;y=y1} {x=x2;y=y2} = {x=f x1 x2; y=f y1 y2} (* こんな風に定義できるはず *) let append' x y= lift (@) x y
ところが実際は、エラーになる
let lift f {x=x1;y=y1} {x=x2;y=y2} = {x=f x1 x2; y=f y1 y2};; Characters 58-60: y=f y1 y2};; ^^ This expression has type float list but is here used with type int list
さて、なにか素敵な方法はないものか。
追記
さかいさんによる、詳しい補足。ありがとうございます。
http://www.tom.sfc.keio.ac.jp/~sakai/d/?date=20080529#p01