在Haskell退状态单子,绑定的如下定义被接受:在勒柯克
type RState s a = s -> (a, s)
bind :: RState s a -> (a -> RState s b) -> RState s b
bind sf f = \s ->
let (a, s'') = sf s'
(b, s') = f a s
in (b, s'')
我怎样才能获得通过勒柯克接受了类似的定义? 我的尝试是:
Definition RState (S A : Type) : Type := S -> A * S.
Definition bind (S A B : Type) (sf : RState S A) (f : A -> RState S B) : RState S B :=
fun s =>
let (a, s'') := sf s' in
let (b, s') := f a s in
(b, s'').
但它失败,出现以下错误信息:
Error: The reference s' was not found in the current environment.
诀窍工作哈斯克尔因为'let'表达两个绑定相互递归。 IDK它如何在Coq中工作,但我猜是有某种'mutual'关键字? –
您还需要使用良好的关系证明终止。我不确定这是否有可能在没有在bind中使用某种额外的(证明)参数(也许是特定的有用的关系)。 –