可以具有以下多态函数
let id x = x;;
let compose f g x = f (g x);;
let rec fix f = f (fix f);; (*laziness aside*)
Run Code Online (Sandbox Code Playgroud)
是为类型/类型构造函数或模块/仿函数编写的?我试过了
type 'x id = Id of 'x;;
type 'f 'g 'x compose = Compose of ('f ('g 'x));;
type 'f fix = Fix of ('f (Fix 'f));;
Run Code Online (Sandbox Code Playgroud)
对于类型但它不起作用.
这是类型的Haskell版本:
data Id x = Id x
data Compose f g x = Compose (f (g x))
data Fix f = Fix (f (Fix f))
-- …Run Code Online (Sandbox Code Playgroud)