Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

freq-with-sig-abstract: compilation succeeds #49

Open
dijkstracula opened this issue Dec 28, 2017 · 0 comments
Open

freq-with-sig-abstract: compilation succeeds #49

dijkstracula opened this issue Dec 28, 2017 · 0 comments

Comments

@dijkstracula
Copy link

Dear Real World OCaml authors,

When following the signatures and abstract types section of Chapter 4, the compilation that should fail for lack of concrete type information hiding actually succeeds.

I can confirm my code matches the version from the book repo:

$ for FILE in "jbuild" "counter.mli" "counter.ml" "freq.ml"; do test $(curl -s https://raw.githubusercontent.com/realworldocaml/examples/v2-sexp/code/files-modules-and-programs/freq-with-sig-abstract/$FILE | md5) = $(md5 -q $FILE) && echo "$FILE matches repo" || echo "$FILE differs"; done
jbuild matches repo
counter.mli matches repo
counter.ml matches repo
freq.ml matches repo

But instead of the expected error message, I get

$ jbuilder clean
$ jbuilder build freq.bc
    ocamldep freq.depends.ocamldep-output
    ocamldep freq.dependsi.ocamldep-output
      ocamlc counter.{cmi,cmti}
      ocamlc counter.{cmo,cmt}
      ocamlc freq.bc
$ echo $?
0

Mysteriously, however, the expected error appears if I manually import Counter in the toplevel:

─( 14:18:23 )─< command 1 >───────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # open Counter;;
─( 14:18:24 )─< command 2 >───────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # let build_counts () =
  In_channel.fold_lines In_channel.stdin ~init:[] ~f:Counter.touch;;
Error: This expression has type t -> string -> t                                                                            
but an expression was expected of type 'a list -> Base.string -> 'a list
Type t is not compatible with type 'a list

So perhaps jbuilder is being overly smart? I'm running $ jbuilder --version 1.0+beta10.

My opam configuration:

# Global variables from the environment

ocaml-version        4.04.1               # The version of the currently used OCaml compiler
opam-version         1.2.1                # The currently running OPAM version
compiler             4.04.1               # The name of the current OCaml compiler (may be more specific than the version, eg: "4.01.0+fp", or "system")
preinstalled         false                # Whether the compiler was preinstalled on the system, or installed by OPAM
switch               4.04.1               # The local name (alias) of the current switch
jobs                 1                    # The number of parallel jobs set up in OPAM configuration
ocaml-native         true                 # Whether the OCaml native compilers are available
ocaml-native-tools   true                 # Whether the native ".opt" version of the OCaml toolchain is available
ocaml-native-dynlink true                 # Whether native dynlink is available on this installation
arch                 x86_64               # The current arch, as returned by "uname -m"

Thanks!
Nathan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant