realworldocaml / examples

All the examples in Real World OCaml
The Unlicense
376 stars 81 forks source link

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

Open dijkstracula opened 6 years ago

dijkstracula commented 6 years ago

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