简体   繁体   English

如何使Ocaml函数的参数成为可变的int?

[英]How to make the parameter of an Ocaml function be a mutable int?

I want to make a function in which the parameter is mutable. 我想做一个参数可变的函数。 I'm familiar with let a = ref 0 but how can i make "a" be a parameter for my function? 我熟悉let a = ref 0但是如何使“ a”成为函数的参数?

If you ask Ocaml nicely, it will infer the right type for you: 如果您很好地询问Ocaml,它将为您推断出正确的类型:

 let incr x =  x:= !x + 1

val incr : int ref -> unit = < fun > val incr:int ref-> unit = <乐趣>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM