admin管理员组文章数量:1122832
(I am learning the OCaml and this may be a naive question.)
I use below code to define a named function a
:
utop # let a = fun x -> x+1;;
val a : int -> int = <fun>
Note that the leading val a
clearly shows up as the name of the function.
Then I tried to see the type info of the function a
:
utop # a;;
- : int -> int = <fun>
There's a leading -
, which means anonymous.
But I have given it a name a
.
Why is it not displayed?
(I am learning the OCaml and this may be a naive question.)
I use below code to define a named function a
:
utop # let a = fun x -> x+1;;
val a : int -> int = <fun>
Note that the leading val a
clearly shows up as the name of the function.
Then I tried to see the type info of the function a
:
utop # a;;
- : int -> int = <fun>
There's a leading -
, which means anonymous.
But I have given it a name a
.
Why is it not displayed?
Share Improve this question edited yesterday smwikipedia asked yesterday smwikipediasmwikipedia 64k96 gold badges326 silver badges503 bronze badges 2 |1 Answer
Reset to default 1The REPL reads the line
a;;
as an anonymous toplevel expression, which returns a value of type int->int
.
This is the same behaviour as you see with
Array.iteri (fun n x -> a.(n) <- x + 1) a
- : unit = ()
with a slightly unusual return type for the expression.
If you want to have information on a value, you can use the #show
toplevel directive:
#show a;;
val a: int -> int
本文标签: ocamlWhy a named function is still displayed as anonymous in utopStack Overflow
版权声明:本文标题:ocaml - Why a named function is still displayed as anonymous in utop? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736282628a1926703.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
:
? That would be redundant. – Naïm Favier Commented yesterdaya
has a name, the value thata
is bound to (which is what gets printed) does not; it is just a function. This is not specific to functions – if youlet a = 1;;
, thena;;
shows- : int = 1
. – molbdnilo Commented 11 hours ago