Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

L letter matters.

# 99L;;
- : int64 = 99L
# 99l;;
- : int32 = 99l
# 99;;
- : int = 99
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top