Created
January 15, 2014 04:04
-
-
Save hkoba/8430579 to your computer and use it in GitHub Desktop.
Mysterious "open Core.Std" effect. (taken from Real World OCaml PDF edition, with mod)
I want to know what is done under the hood.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* open Core.Std | |
When I opened Core.Std here, no problem occured. But... | |
*) | |
module type ID = sig | |
type t | |
val of_string : string -> t | |
val to_string : t -> string | |
end | |
module String_id = struct | |
type t = string | |
let of_string x = x | |
let to_string x = x | |
end | |
(* When I moved "open Core.Std" here...*) | |
open Core.Std | |
module Hostname : sig | |
include ID | |
val mine : unit -> t | |
end = struct | |
include String_id | |
let mine = Unix.gethostname | |
end | |
(* ...I got this error: | |
File "nestedmod1_ng.ml", line 23, characters 6-66: | |
Error: Signature mismatch: | |
... | |
Values do not match: | |
val mine : unit -> string | |
is not included in | |
val mine : unit -> t | |
File "nestedmod1_ng.ml", line 22, characters 2-22: | |
Expected declaration | |
File "nestedmod1_ng.ml", line 25, characters 6-10: Actual declaration | |
Actually I had to rewrite above as: | |
let mine () = of_string (Unix.gethostname ()) | |
But it seems to me 'Unix.gethostname' has exactly same type of 'Core.Std.Unix.gethostname': | |
utop # Unix.gethostname;; | |
- : unit -> string = <fun> | |
utop # Core.Std.Unix.gethostname;; | |
- : unit -> string = <fun> | |
So now, I'm very curious about what "open Core.Std" actually does. | |
Do that change meanings of 'string' or any other OCaml constructs | |
like 'module', '()'...? | |
*) |
To detect this kind of overwriting errors, we should add 'warn_A' flag to _tags
file, like this:
true: warn_A
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://twitter.com/camloeba/status/423337850231201792
Thank you!