문제

Lets say you had some code like this

type foo_t = int64 

let do_something_with_foo (f : foo_t) = (* left to your imagination *)

And you wanted to call it with a constant "foo", like this:

do_something_with_foo 99

How do you convince the compiler/interpreter that your constant 99 is actually a foo_t?

도움이 되었습니까?

해결책

Use do_something_with_foo 99L. The constant 99 has type int, 99L has type int64.

This has nothing to do with the type alias foo_t = int64. As long as the definition of foo_t is visible (i.e. not masked by the signature of a containing module), any value of type int64 also has type foo_t and vice-versa.

다른 팁

L letter matters.

# 99L;;
- : int64 = 99L
# 99l;;
- : int32 = 99l
# 99;;
- : int = 99
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top